Python 如何在 Windows 上运行 celery?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37255548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:07:49  来源:igfitidea点击:

How to run celery on windows?

pythoncelery

提问by nicks

How to run celery worker on Windows without creating Windows Service? Is there any analogy to $ celery -A your_application worker?

如何在不创建 Windows 服务的情况下在 Windows 上运行 celery worker?有什么类比$ celery -A your_application worker吗?

采纳答案by nicks

It's done the same way as in Linux. Changing directory to module containing celery task and calling "c:\python\python" -m celery -A module.celery workerworked well.

它的完成方式与在 Linux 中相同。将目录更改为包含 celery 任务和调用的模块"c:\python\python" -m celery -A module.celery worker效果很好。

回答by Samuel Chen

Celery 4.0+does not officially support window already. But it still works on window for some development/test purpose.

Celery 4.0+尚未正式支持窗口。但它仍然适用于某些开发/测试目的的窗口。

Use eventletinstead as below:

eventlet改为使用如下:

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

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

它在window 10++上对我celery 4.1有用python 3

This solutionsolved the following exception:

此解决方案解决了以下异常:

[2017-11-16 21:19:46,938: ERROR/MainProcess] Task handler raised error: ValueError('need more than 0 values to unpack',)
Traceback (most recent call last):
  File "c:\users\wchen8\work\venv\weinsta\lib\site-packages\billiard\pool.py", line 358, in workloop
    result = (True, prepare_result(fun(*args, **kwargs)))
  File "c:\users\wchen8\work\venv\weinsta\lib\site-packages\celery\app\trace.py", line 525, in _fast_trace_task
    tasks, accept, hostname = _loc
ValueError: need more than 0 values to unpack

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

===== 更新 2018-11 =====

Eventlet has an issue on subprocess.CalledProcessError:

Eventlet 在 subprocess.CalledProcessError 上有问题:

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

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

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

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

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

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

So try geventinstead.

所以试试吧gevent

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

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

这对我有用window 10+ celery 4.2+python 3.6

回答by kumarz

yes:

是的:

celery -A your_application -l info

also note Celery have dropped support for Windows(since v4), so best to

还要注意 Celery 已经放弃了对 Windows(since v4) 的支持,所以最好

pip install celery==3.1.25

3.1.25 was the last versionthat works on windows(just tested on my win10 machine). Didn't need to downgrade flower(browser monitor for celery) though.

3.1.25 是最后一个适用于 windows 的版本(刚刚在我的 win10 机器上测试过)。不过不需要降级花(芹菜的浏览器监视器)。

See also the FAQ for Windows

另请参阅Windows 常见问题解答

回答by Bjoern Stiel

There are two workarounds to make Celery 4 work on Windows:

有两种解决方法可以让 Celery 4 在 Windows 上运行:

  • use eventlet, gevent or solo concurrency pool (if your tasks as I/O and not CPU-bound)
  • set the environment variable FORKED_BY_MULTIPROCESSING=1 (this is what actually causes the underlying billiard package to to fail under Windows since version 4)
  • 使用 eventlet、gevent 或单独的并发池(如果您的任务是 I/O 而不是 CPU 绑定)
  • 设置环境变量 FORKED_BY_MULTIPROCESSING=1(这实际上是导致底层台球包从版本 4 开始在 Windows 下失败的原因)

See https://www.distributedpython.com/2018/08/21/celery-4-windowsfor more details

有关更多详细信息,请参阅https://www.distributedpython.com/2018/08/21/celery-4-windows



回答by Teja Muvva

I have run celery task using RabbitMQ server. RabbitMq is better and simple than redis broker

我已经使用 RabbitMQ 服务器运行了 celery 任务。RabbitMq 比 redis broker 更好更简单

while running celery use this command "celery -A project-name worker --pool=solo -l info" and avoid this command "celery -A project-name worker --loglevel info"

在运行 celery 时使用此命令“celery -A project-name worker --pool=solo -l info”并避免使用此命令“celery -A project-name worker --loglevel info”

回答by vijay Rajput

You can still use celery 4 0+ with Windows 10+ Just use this command "celery -A projet worker - -pool=solo - l info" instead of "celery - A project worker -l info

您仍然可以在 Windows 10+ 中使用 celery 4 0+ 只需使用此命令“celery -A projet worker - -pool=solo -l info”而不是“celery - A project worker -l info”

回答by Pourya

I've made a .bat file besides my manage.py file with this code:

除了使用以下代码的 manage.py 文件之外,我还制作了一个 .bat 文件:

title CeleryTask
::See the title at the top.
cd 
cmd /k celery -A MainProject worker -l info

so each time I want to run celery, I just double-click this batch file and it runs perfectly. And the fact that you can't use celery 4 on windows is true.

所以每次我想运行 celery 时,我只需双击这个批处理文件,它就可以完美运行。并且您不能在 Windows 上使用 celery 4 的事实是正确的。