当我使用celery
+ gevent
执行使用subprocess
模块的任务时,我会跟踪堆栈跟踪:
Traceback (most recent call last):
File "/home/venv/admin/lib/python2.7/site-packages/celery/task/trace.py", line 228, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/venv/admin/lib/python2.7/site-packages/celery/task/trace.py", line 415, in __protected_call__
return self.run(*args, **kwargs)
File "/home/webapp/admin/webadmin/apps/loggingquarantine/tasks.py", line 107, in release_mail_task
res = call_external_script(popen_obj.communicate)
File "/home/webapp/admin/webadmin/apps/core/helpers.py", line 42, in call_external_script
return func_to_call(*args, **kwargs)
File "/usr/lib64/python2.7/subprocess.py", line 740, in communicate
return self._communicate(input)
File "/usr/lib64/python2.7/subprocess.py", line 1257, in _communicate
stdout, stderr = self._communicate_with_poll(input)
File "/usr/lib64/python2.7/subprocess.py", line 1287, in _communicate_with_poll
poller = select.poll()
AttributeError: 'module' object has no attribute 'poll'
我的manage.py
看起来跟着(在那里做monkeypatch):
#!/usr/bin/env python
from gevent import monkey
import sys
import os
if __name__ == "__main__":
if not 'celery' in sys.argv:
monkey.patch_all()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webadmin.settings")
from django.core.management import execute_from_command_line
sys.path.append(".")
execute_from_command_line(sys.argv)
有没有理由说芹菜任务表现得好像没有正确修补?
P.S。奇怪的是,我在Macos上的本地设置工作正常,而我在Centos下得到这样的例外(所有包版本都是相同的,init和配置脚本也是如此)
答案 0 :(得分:-1)
gevent中没有用于轮询的模拟,因此monkey.patch_all
删除了gevent.select不模拟的轮询机制:poll,epoll,kqueue,kevent。请参阅gevent.monkey – Make the standard library cooperative。