简体   繁体   English

Python Celery socket.error:[Errno 61]连接被拒绝

[英]Python Celery socket.error: [Errno 61] Connection refused

I am using Celery 3.0 and have the configuration file like below. 我正在使用Celery 3.0,并具有如下配置文件。

celeryconfig.py 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

tasks.py task.py

import celery

@celery.task
def function(x,y):
    return x + y

and function.py 和function.py

from tasks import function

print function.delay(4,4).get()

I run the application with following command 我使用以下命令运行该应用程序

celeryd --loglevel=INFO --config=celeryconfig

Everything is working great till now. 到目前为止,一切都很好。 I have redis and celery running and getting answers. 我有redis和芹菜运行并得到答案。

But when I run the function command from another file called parallelizer, 但是,当我从另一个名为parallelizer的文件中运行function命令时,

I get the socket error, 我收到套接字错误,

 socket.error: [Errno 61] Connection refused

My file is like below, 我的档案如下

from examples.dummy.tasks import function
print function.delay(4,4).get()

Any ideas ? 有任何想法吗 ?

Had the same problem, ended up realizing that rabbitmq and redis processes were stoped. 有同样的问题,最终意识到rabbitmqredis过程进行了采空。

On mac, if those services were installed via homebrew, then you can verify whether those services are running by running following command on terminal, 在Mac上,如果这些服务是通过自制软件安装的,则可以通过在终端上运行以下命令来验证这些服务是否正在运行,

brew services list

can restart services by, (if installed via brew ) 可以通过以下方式重新启动服务(如果通过brew安装)

brew services restart rabbitmq
brew services restart redis

I had the same problem and the issue was that I missed this code in my project's __init__.py: 我有同样的问题,问题是我在项目的__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

I hope it will be useful to someone out there... 我希望这对外面的人有用。

Problem was, 问题是

I was running celeryconfig.py under from a different path than my parallelizer. 我从与并行器不同的路径下运行celeryconfig.py。

When I carried the celeryconfig.py to same path with paralellizer it fixed the issue. 当我将celeryconfig.py与paralellizer携带到同一路径时,它解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM