- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我希望使用 Celery/RabbitMQ 在 Windows 7 和 Python 3.3 上的 Flask 应用程序中运行常规间隔任务。 Pip 安装:
billiard==3.3.0.10
celery==3.1.6
代码:
### celeryapp.py ###
from celery import Celery
from twend import config, app
def make_celery(app):
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
celery_pipe = make_celery(app)
celery_pipe.config_from_object(config)
### tasks.py ###
from celery import task
from twend.celeryapp import celery_pipe as celery
@celery.task()
def add_together(a, b):
return a + b
### config.py ###
CELERY_BROKER_URL = 'amqp://'
CELERY_RESULT_BACKEND = 'amqp://'
CELERY_ACCEPT_CONTENT = ['json']
当我尝试启动 worker 时,我得到:
ERROR/MainProcess] Unrecoverable error: PicklingError(
"Can't pickle <class 'module'>: attribute lookup builtins.module failed",)
Traceback (most recent call last):
File "c:\Python33\twend\lib\site-packages\celery\worker\__init__.py", line 212
, in start
self.blueprint.start(self)
File "c:\Python33\twend\lib\site-packages\celery\bootsteps.py", line 123, in s
tart
step.start(parent)
File "c:\Python33\twend\lib\site-packages\celery\bootsteps.py", line 373, in s
tart
return self.obj.start()
File "c:\Python33\twend\lib\site-packages\celery\concurrency\base.py", line 12
7, in start
self.on_start()
File "c:\Python33\twend\lib\site-packages\celery\concurrency\prefork.py", line
112, in on_start
**self.options)
File "c:\Python33\twend\lib\site-packages\billiard\pool.py", line 966, in __in
it__
self._create_worker_process(i)
File "c:\Python33\twend\lib\site-packages\billiard\pool.py", line 1059, in _cr
eate_worker_process
w.start()
File "c:\Python33\twend\lib\site-packages\billiard\process.py", line 139, in s
tart
self._popen = Popen(self)
File "c:\Python33\twend\lib\site-packages\billiard\forking.py", line 263, in _
_init__
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "c:\Python33\twend\lib\site-packages\billiard\_reduction3.py", line 60, i
n dump
ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'module'>: attribute lookup builtins.
module failed
(twend) c:\Python33\twend>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\Python33\twend\lib\site-packages\billiard\forking.py", line 457, in m
ain
self = load(from_parent)
EOFError
这https://github.com/celery/django-celery/issues/228似乎是一个类似的问题,但已在我使用的 Celery 版本中修复。
我还读到 Windows 对 pickle 有限制,但我不确定实际被 pickle 的是什么。
最佳答案
Celery 使用酸洗来序列化任务和结果。我看到您已经将配置设置为仅接受 json 序列化,因此也许您可以通过添加更多配置行来解决您的问题:
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
这样就完全不用pickle了,Celery的序列化全部使用json来完成。这在理论上会导致性能下降,但我通过这种方式解决了我的 Flask 应用程序中的类似问题并且没有发现任何性能问题。 YMMV
关于python - 在 Flask 应用程序中开始使用 Celery 时出现 PicklingError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20350629/
我在cmd中发起了焰火,并在下面进行了表演,以提高我的技能。。当我执行a.take(1)时,我得到“_ickle.PicklingError:无法序列化对象:IndexError:tuple inde
我有以下两个数据帧:df_whitelist和df_text +-------+--------------------+ |keyword| whitelist_terms | +------
执行示例 from multiprocessing import Process def f(name): print 'hello', name if __name__ == '__main
我正在做一个 Python/Django/Wagtail 项目,我有一些 api 可以返回一些分页的文章。它是这样的: 在网址中: url(r'^morearticles/', views.get_l
在多处理模块中使用 Pool.map_async()(以及 Pool.map())时遇到问题。我已经实现了一个并行循环函数,只要 Pool.map_async 的函数输入是“常规”函数,它就可以正常工
我在测试使用 mock 调用方法时遇到问题-- 作为一个简单的例子,假设方法是 os.getcwd .我想测试我自己的功能,pickle_wdir , 正在调用 os.getcwd如预期。但是,我正在
你知道解决这个问题的方法吗: [Thu Jul 08 19:15:38 2010] [error] [client 79.162.31.162] mod_wsgi (pid=3072): Except
下面的最小示例使用了一个虚拟装饰器,它只是在构造装饰类的对象时打印一些消息。 import pickle def decorate(message): def call_decorator(f
我有以下代码: def decorator(func): @functools.wraps(func) def other_func(): print('other f
尝试围绕执行 map_async() 的函数编写一些单元测试手术。更具体地说,我想确认在某个进程中发生异常时某些文件会被清理。下面提供了具有意图的示例伪代码。 foo.py def write_chu
我正在尝试编写一个基于 multiprocessing 的便捷函数库,它接受任何函数和参数,并使用多个进程运行该函数。我正在导入以下文件“MultiProcFunctions.py”: import
在没有修改的情况下运行 Elephas 示例时出错:(即使使用 git 版本 pip install --no-cache-dir git+git://github.com/maxpumperla/e
我正在尝试根据本教程的指导为 Python sklearn 管道创建自定义转换器:http://danielhnyk.cz/creating-your-own-estimator-scikit-lea
我想在给定目录中的所有图像中搜索冲浪,并保存它们的关键点和描述符以供将来使用。我决定使用pickle,如下所示: #!/usr/bin/env python import os import pick
很抱歉,我无法用更简单的示例重现该错误,并且我的代码太复杂而无法发布。如果我在 IPython shell 而不是常规的 Python 中运行程序,一切都会顺利进行。 我查阅了有关此问题的一些以前的注
我在 dataproc 上运行 pyspark 作业时遇到此错误。可能是什么原因 ? 这是错误的堆栈跟踪。 File "/usr/lib/python2.7/pickle.py", line 33
我希望使用 Celery/RabbitMQ 在 Windows 7 和 Python 3.3 上的 Flask 应用程序中运行常规间隔任务。 Pip 安装: billiard==3.3.0.10 ce
这个问题在这里已经有了答案: Can't pickle when using multiprocessing Pool.map() (14 个答案) 关闭 5 年前。 我正在尝试使用 python
当我尝试使用以下命令将表复制到 cassandra 时: copy images from 'images.csv' 我得到错误: 'PicklingError: Can't pickle : att
我从我的 GAE Python 应用程序中的这行代码中收到 PicklingError: deferred.defer(email_voters_begin, ekey, voter_list) 这三
我是一名优秀的程序员,十分优秀!