我正在尝试按照文档开始使用 celery,但在示例代码中遇到了难以调试的问题。我不知道我遇到的是同一个问题的两个方面,还是两个独特的问题。我可以通过 shell 连接到 SQS 队列,但不能使用 django。我不知道这种行为与导入芹菜与导入任务的问题有什么关系。
这里的“入门”指南:http: //celery.github.com/celery/getting-started/first-steps-with-celery.html#running-the-celery-worker-server
显示代码
from celery import Celery
如果我从 python shell 运行此代码,则此代码有效,但是,如果我在 eclipse 的 tasks.py 中的 django 项目中执行此操作,则会收到错误 Unresolved Import: Celery。
这里有一个单独的指南:http: //celery.github.com/celery/django/first-steps-with-django.html for django,而是使用
from celery import task
但是,当我继续本教程并致电时,它可以很好地解决
add.delay(2, 2)
我遇到连接失败,看起来它可能仍在尝试使用 rabbitmq 而不是 SQS 我有我的 django 项目设置来使用(它有效,我可以从亚马逊的 Web 界面看到 SQS 队列,我可以制作如果我使用 from celery import Celery 从 shell 执行所有操作,则连接)。这是相关的堆栈跟踪:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/celery/app/task.py", line 343, in delay
return self.apply_async(args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/task.py", line 458, in apply_async
with app.producer_or_acquire(producer) as P:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 247, in producer_or_acquire
with self.amqp.producer_pool.acquire(block=True) as producer:
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 705, in acquire
R = self.prepare(R)
File "/usr/local/lib/python2.7/dist-packages/kombu/pools.py", line 54, in prepare
p = p()
File "/usr/local/lib/python2.7/dist-packages/kombu/pools.py", line 45, in <lambda>
return lambda: self.create_producer()
File "/usr/local/lib/python2.7/dist-packages/kombu/pools.py", line 42, in create_producer
return self.Producer(self._acquire_connection())
File "/usr/local/lib/python2.7/dist-packages/celery/app/amqp.py", line 160, in __init__
super(TaskProducer, self).__init__(channel, exchange, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/kombu/messaging.py", line 83, in __init__
self.revive(self.channel)
File "/usr/local/lib/python2.7/dist-packages/kombu/messaging.py", line 174, in revive
channel = self.channel = maybe_channel(channel)
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 879, in maybe_channel
return channel.default_channel
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 617, in default_channel
self.connection
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 610, in connection
self._connection = self._establish_connection()
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 569, in _establish_connection
conn = self.transport.establish_connection()
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/amqplib.py", line 279, in establish_connection
connect_timeout=conninfo.connect_timeout)
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/amqplib.py", line 90, in __init__
super(Connection, self).__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/amqplib/client_0_8/connection.py", line 129, in __init__
self.transport = create_transport(host, connect_timeout, ssl)
File "/usr/local/lib/python2.7/dist-packages/amqplib/client_0_8/transport.py", line 281, in create_transport
return TCPTransport(host, connect_timeout)
File "/usr/local/lib/python2.7/dist-packages/amqplib/client_0_8/transport.py", line 85, in __init__
raise socket.error, msg
socket.error: [Errno 111] Connection refused
在 settings.py 中,我使用我的 SQS url 正确配置了 BROKER_URL(并且密码中没有正斜杠,这在过去显然是一个问题)。
所以
- 为什么“from celery import Celery”可以从 python shell 工作,但不能在 django 项目的 eclipse 中工作?
- 为什么按照 django 教程中的说明会导致连接被拒绝错误(amqplib 引用是否意味着它正在尝试使用 rabbitmq 而不是 SQS)?