How to test celery with django on a windows machine

眉间皱痕 提交于 2019-12-01 12:29:09

Celery (since version 4 as pointed out by another answer) does not support Windows (source: http://docs.celeryproject.org/en/latest/faq.html#does-celery-support-windows). Even so, you have some options:

1) Use task_always_eager=True. This will run your tasks synchronously – with this, you can verify that your code is doing what it's supposed to do. Running tasks synchronously works even on Windows.

More info: http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-task_always_eager

2) Use WSL (Windows Subsystem for Linux).

More info: https://docs.microsoft.com/en-us/windows/wsl/install-win10#install-the-windows-subsystem-for-linux

3) Use Docker for Windows. You can run Celery Worker(s) and Celery Beat inside the container.

More info: https://docs.docker.com/docker-for-windows/

Personally, I use option 1) for unit testing and option 2) for development.

There are two workarounds to make Celery work (natively) on Windows - and therefore be able to test it as if it were on Linux.

  • use eventlet, gevent or solo concurrency pool (if your tasks as I/O and not CPU-bound)
  • set the environment variable FORKED_BY_MULTIPROCESS=1 (this is what actually causes the underlying billiard package to to fail under Windows since version 4)

https://www.distributedpython.com/2018/08/21/celery-4-windows/

Actually you cant. Since Celery 4.x, Windows is no longer supported due to lack of resources. This is what official documentation of celery says.

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