修复Celery问题“无法腌制<class'module'>:内置的属性查找模块失败

时间:2019-08-02 07:19:41

标签: django redis django-celery celery-task

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

<input type="checkbox" id="checkA" unchecked />
<label for="checkA" id="checkALabel" onclick="{
    const $ = x => document.getElementById(x);

    // Reject if user tries to check checkA although checkB is false
    if (!$('checkA').checked && !$('checkB').checked) {
        alert('rejected');
        return false;
    }
    return true;
}">[check a]</label>

<input type="checkbox" id="checkB" onchange="{
    const $ = x => document.getElementById(x);

    // If [checkB is true but checkA not checked] then check checkA
    // or if [checkB is false and checkA checked] then uncheck checkA
    if ($('checkA').checked ^ $('checkB').checked) {
        $('checkALabel').click();
        if (!$('checkA').checked) {
            alert('disabled')
        }
    }
}" unchecked />
<label for="checkB">[check b]</label>

我得到这个长错误:

celery -A acmetelbi worker --loglevel=info

我挠头,不知道如何解决此问题。请帮忙!

我在Django应用中创建任务的代码。

[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

并在settings.py中:

其他芹菜设置

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

1 个答案:

答案 0 :(得分:0)

花了很多天的研究后,我得出了芹菜在Windows上有局限性的结论,如果您想在Windows上运行celery,那么必须使用gevent命令运行它:

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

然后运行此工作进程后,相应地启动芹菜拍子以开始处理。