阅读文档本地安装:Celery ValueError:信号仅在主线程中有效 [英] Read the Docs local install: Celery ValueError: signal only works in main thread

查看:131
本文介绍了阅读文档本地安装:Celery ValueError:信号仅在主线程中有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地安装了readthedocs,并在尝试导入项目时收到ValueError异常.我使用的是5.1.0版本,在celery 4.1.1上的Debian Buster上运行python 3.6(来自需求文件).

I have a local readthedocs install and get a ValueError exception when trying to import a project. I'm on release 5.1.0, running python 3.6 on Debian buster with celery 4.1.1 (from the requirements files).

在debug.log中:

From the debug.log:

[19/May/2020 23:31:11] celery.app.trace:124[24]: INFO Task readthedocs.projects.tasks.send_notifications[39551573-cfe1-46c1-b7e2-28bde20fd962] succeeded in 0.005342413205653429s: None
[19/May/2020 23:31:11] celery.app.trace:124[24]: INFO Task readthedocs.oauth.tasks.attach_webhook[119bed10-cacc-450c-bd51-822e96faffd7] succeeded in 0.016763793770223856s: False
[19/May/2020 23:31:11] celery.app.trace:249[24]: ERROR Task readthedocs.projects.tasks.update_docs_task[b6c22791-f1c6-4ddb-b64a-68d141580c30] raised unexpected: ValueError('signal only works in main thread',)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 375, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/readthedocs.org/readthedocs/projects/tasks.py", line 448, in update_docs_task
    signal.signal(signal.SIGTERM, sigterm_received)
  File "/usr/local/lib/python3.6/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

我正在使用 manage.py runserver 来运行readthedocs,所以我尝试了-noreload 选项无效,而-nothreading选项,这将导致页面永久挂起.

I'm using manage.py runserver to run readthedocs, so I tried the --noreload option which has no effect, and the --nothreading option, which causes pages to hang forever.

推荐答案

为使本地安装正常工作,您需要运行celery worker,这是我以前没有做过的(并且不在readthedocs文档中).我正在使用docker compose,并运行了一个名为 celery 的单独服务,该服务使用与主readthedocs服务相同的图像(安装django和readthedocs的自定义docker图像).

In order to get a local installation working you need to run a celery worker, which I wasn't doing before (and is not in the readthedocs docs). I'm using docker compose, and ran a separate service called celery that uses the same image as the main readthedocs service (custom docker image that installs django and readthedocs).

celery -A readthedocs.worker worker -E -l info -Q celery,web

此外,我在Django配置中具有以下设置:

Additionally, I have these settings in my Django config:

BROKER_URL = os.getenv('REDIS_URL')
CELERY_RESULT_BACKEND = os.getenv('REDIS_URL')
CELERY_ALWAYS_EAGER = False

我的撰写配置中有一个简单的redis服务:

I have a simple redis service in my compose config:

redis:
  image: redis

然后我将 REDIS_URL = redis://redis:6379/0 作为我的readthedocs和celery服务上的环境变量.

I then have REDIS_URL=redis://redis:6379/0 as an environment variable on my readthedocs and celery services.

有些无关,但我也停止使用 python manage.py runserver 并将其替换为uwsgi进行生产.

Somewhat unrelated but I also stopped using python manage.py runserver and replaced it with uwsgi for production.

uwsgi \
    --http :80 \
    --wsgi-file readthedocs/wsgi.py \
    --static-map /static=./static \
    --master --processes 4 --threads 2

这篇关于阅读文档本地安装:Celery ValueError:信号仅在主线程中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆