我正在尝试让工作人员在Python2上运行,并在Python3上运行客户端 我注意到,如果我从Python3启动客户端,工作代码似乎也在Python3上运行,而不是Python2。
我该如何解决这个问题?我的工作代码位于Python2上,使用它的客户端必须在Python3上运行?
这就是我设置它的方式。
from celery import Celery
import time
app = Celery('tasks', backend='redis://localhost', broker='redis://localhost')
app.conf.update(
task_serializer='json',
accept_content=['json'], # Ignore other content
result_serializer='json',
timezone='Europe/Oslo',
enable_utc=True,
)
@app.task
def add(x, y):
time.sleep(5)
print "Trying to process task" # This can run only on Python2, and not Python3
return x + y
执行命令: 芹菜 - 任务工作者--loglevel = info -c 1
from celery import Celery
from tasks import add
import time
app = Celery('tasks', backend='redis://localhost', broker='redis://localhost')
app.conf.update(
task_serializer='json',
accept_content=['json'], # Ignore other content
result_serializer='json',
timezone='Europe/Oslo',
enable_utc=True,
)
result = add.delay(4, 8)
result.get()
这是我在执行client.py(在python3中)时遇到的错误
Traceback (most recent call last):
File "client.py", line 2, in <module>
from tasks import add
File "/home/vishal/work/yobi/expr/tasks.py", line 17
print "Trying to process task"
这不是意外吗?我猜想工作者代码应该在Python2上运行,而不是Python3。