2013-10-21 135 views
3

工作,当我使用celery + gevent的任务使用subprocess模块我得到以下堆栈跟踪:芹菜任务不GEVENT

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长相以下(做猴补丁存在):

#!/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下获得这样的例外(所有的软件包版本都是相同的,初始化和配置脚本)

+0

请参阅http://stackoverflow.com/q/8678307/512251 – user

+0

你用什么脚本启动你的工人? –

+0

@btoueg [celeryd](https://gist.github.com/Novarg/7199719#file-celeryd) 和 [的sysconf/celeryd](https://gist.github.com/Novarg/7199701# file-celeryd-sysconf) – Novarg

回答

-1

没有模拟gevent中的轮询,所以monkey.patch_all删除轮询机制,选择不模拟:poll,epoll,kqueue,kevent。见gevent.monkey – Make the standard library cooperative

+0

是的,但是'subprocess'模块实际上检查'select'模块中'poll'是否可用。如果它试图使用'_communicate_with_poll',那么当'subprocess'被导入的时候'select'没有被修补,但是如果芹菜通过manage.py启动并且在那里修补,怎么会这样。 – Novarg