fastapi-practices/fastapi_best_architecture

Celery with asyncio?

downdawn opened this issue · 4 comments

Hi, @wu-clan

Celery scheduled tasks cannot be executed

bdb52e620133cb39d87751f53ed28ea

Solutions related to asyncio
https://stackoverflow.com/questions/39815771/how-to-combine-celery-with-asyncio

5b0e766934b4c6826ddfc9611064a87

The method above uses async_to_sync to forcibly convert to a synchronous method, which runs normally on the Windows 10 system, but requires additional configuration.

# windows 下需要设置环境变量,不推荐使用 windows 下开发 celery
# https://github.com/celery/celery/pull/4078
#
import os

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

In the CentOS 7 system environment, after deployment using Supervisor and Gunicorn, observe it several times and an exception may occur.
image

If Celery cannot be compatible with asyncio, then performing database operations within tasks will be affected.

Hi, @downdawn
Has successfully run the asynchronous task with a temporary solution, see pr TODO for details.

nice