我正在使用 Celery 3.0 并具有如下所示的配置文件。
celeryconfig.py
BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_IMPORTS = ("tasks", )
CELERY_TASK_RESULT_EXPIRES = 300
任务.py
import celery
@celery.task
def function(x,y):
return x + y
和函数.py
from tasks import function
print function.delay(4,4).get()
我使用以下命令运行应用程序
celeryd --loglevel=INFO --config=celeryconfig
到目前为止一切都很顺利。我有 redis 和 celery 正在运行并得到答案。
但是当我从另一个名为并行器的文件运行函数命令时,
我收到套接字错误,
socket.error: [Errno 61] Connection refused
我的文件如下,
from examples.dummy.tasks import function
print function.delay(4,4).get()
有什么想法吗?
遇到了同样的问题,最终意识到
rabbitmq
和redis
进程已停止。
在 Mac 上,如果这些服务是通过自制程序安装的,那么您可以通过在终端上运行以下命令来验证这些服务是否正在运行,
brew services list
可以通过以下方式重新启动服务(如果通过
brew
安装)
brew services restart rabbitmq
brew services restart redis
我遇到了同样的问题,问题是我在项目的 __init__.py 中错过了这段代码:
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
我希望它对那里的人有用......
问题是,
我从与并行器不同的路径运行 celeryconfig.py。
当我使用并行器将 celeryconfig.py 带到同一路径时,它解决了问题。
我面临着同样的问题,并尝试了几乎所有开源解决方案,最后我得到了 100% 高效工作的解决方案。
您需要做的就是
里面
项目--->>init.py
文件 你必须添加这两行代码
代码:
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
#Django #celery #redis #celeryconnectionerror #connectionrefused