Celery raises ValueError: not enough values to unpack

谁说胖子不能爱 提交于 2019-12-03 06:20:53

问题


Trying to run simple example with Celery and receiving an exception. RabbitMQ started in a Docker, also tried to start it locally. Celery works on a local Windows host

from celery import Celery

app = Celery('tasks', broker='amqp://192.168.99.100:32774')

@app.task()
def hello():
    print('hello')


if __name__ == '__main__':
    hello.delay()

Excerpt of my error text:

[2017-08-18 00:01:08,628: INFO/MainProcess] Received task: tasks.hello[8d33dbea-c5d9-4938-ab1d-0646eb1a3858] [2017-08-18 00:01:08,632: ERROR/MainProcess] Task handler raised error: ValueError('not enough values to unpack (expected 3, got 0)',) Traceback (most recent call last): File "c:\users\user\celenv\lib\site-packages\billiard\pool.py", line 358, in workloop result = (True, prepare_result(fun(*args, **kwargs))) File "c:\users\user\celenv\lib\site-packages\celery\app\trace.py", line 525, in _fast_trace_task tasks, accept, hostname = _loc ValueError: not enough values to unpack (expected 3, got 0)


回答1:


which celery version? as far as I remember celery doesn't supported in windows since celery 4




回答2:


Celery 4.0+ does not officially support Windows yet. But it still works on Windows for some development/test purposes.

Use eventlet instead as below:

pip install eventlet
celery -A <module> worker -l info -P eventlet

It works for me on Windows 10 + celery 4.1 + python 3.

===== update 2018-11 =====

Eventlet has an issue on subprocess.CalledProcessError:

https://github.com/celery/celery/issues/4063

https://github.com/eventlet/eventlet/issues/357

https://github.com/eventlet/eventlet/issues/413

So try gevent instead.

pip install gevent
celery -A <module> worker -l info -P gevent

This works for me on Windows 10 + celery 4.2 + python 3.6




回答3:


For Celery 4.1 on Windows.

Set an environment variable FORKED_BY_MULTIPROCESSING=1. Then you can simply run celery -A <celery module> worker.




回答4:


I got this error on Windows 7 32bit system. So I did this to make it work.

Add this

`os.environ.setdefault('FORKED_BY_MULTIPROCESSING', '1')` 

before defining a celery instance in myproj/settings.py file in your django project.

It should like like

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproj.settings')
os.environ.setdefault('FORKED_BY_MULTIPROCESSING', '1')

app = Celery('tasks', broker='redis://127.0.0.1:6379/0')

I am using redis as a messaging broker so defined broker='redis://127.0.0.1:6379/0'



来源:https://stackoverflow.com/questions/45744992/celery-raises-valueerror-not-enough-values-to-unpack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!