gpt4 book ai didi

django - 修复 Celery 问题 'can' t pickle : attribute lookup module on builtins failed

转载 作者:行者123 更新时间:2023-12-02 10:48:30 27 4
gpt4 key购买 nike

我在Windows上运行celery 4.1.1并向redis发送请求(在ubuntu上),Redis已正确连接并从Windows端进行了测试。但是当我运行这个命令时

celery -A acmetelbi worker --loglevel=info

我收到这么长的错误:

[tasks]
. accounts.tasks.myprinting
. acmetelbi.celery.debug_task
[2019-08-02 11:46:44,515: CRITICAL/MainProcess] Unrecoverable error:
PicklingErr
or("Can't pickle <class 'module'>: attribute lookup module on builtins
failed",)

Traceback (most recent call last):
File "c:\acmedata\virtualenv\bi\lib\site-
packages\celery\worker\worker.py", line 205, in start
self.blueprint.start(self)
File "c:\acmedata\virtualenv\bi\lib\site-packages\celery\bootsteps.py",
line 119, in start step.start(parent)
File "c:\acmedata\virtualenv\bi\lib\site-packages\celery\bootsteps.py",
line 370, in start return self.obj.start()
File "c:\acmedata\virtualenv\bi\lib\site-
packages\celery\concurrency\base.py",
line 131, in start self.on_start()
File "c:\acmedata\virtualenv\bi\lib\site-
packages\celery\concurrency\prefork.p
y", line 112, in on_start
**self.options)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\pool.py", line
1007 , in __init__ self._create_worker_process(i)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\pool.py", line
1116, in _create_worker_process w.start()
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\process.py",
line 124, in start self._popen = self._Popen(self)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\context.py",
line 383, in _Popen return Popen(process_obj)
File "c:\acmedata\virtualenv\bi\lib\site-
packages\billiard\popen_spawn_win32.py",
line 79, in __init__ reduction.dump(process_obj, to_child)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\reduction.py",
line 99, in dump ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'module'>: attribute lookup
module on builtins failed

(bi) C:\acmedata\bi_solution\acmetelbi>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\spawn.py",
line 165, in spawn_main exitcode = _main(fd)
File "c:\acmedata\virtualenv\bi\lib\site-packages\billiard\spawn.py",
line 207, in _main self = pickle.load(from_parent)
EOFError: Ran out of input

我摸不着头脑,不明白如何解决这个问题。请帮忙!

我在 django 应用程序中创建任务的代码。

@task()
def myprinting(self):
print("I am task")

在settings.py中:

其他 Celery 设置

CELERY_BEAT_SCHEDULE = {
'task-number-one': {
'task': 'accounts.tasks.myprinting',
'schedule': crontab(minute='*/30'),
},

最佳答案

经过几天的研究,我得出的结论是 celery 在 Windows 上有限制,如果你想在 Windows 上运行 celery 那么你必须使用 gevent 命令运行它:

python manage.py celery worker -P gevent --loglevel=INFO

然后在运行此工作进程后相应地启动 celerybeat 来开始处理。

关于django - 修复 Celery 问题 'can' t pickle <class 'module' > : attribute lookup module on builtins failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57321636/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com