简体   繁体   中英

celery task doesn't return result to client

I'm trying to setup a simple worker that will return the result to the client. However, the client blocks forever, and there's no indication of any errors on the server.

The service:

from celery import Celery
import logging

logger = logging.getLogger(__name__)
app = Celery('Service', broker='amqp://localhost', backend='rpc://localhost')

@app.task()
def operation(x):
    logger.info(x)
    return 1

The client:

from celery_test.service import operation

rv = operation.delay('foo')
print rv.ready()
print rv.get()

Server log:

[2015-07-08 14:15:02,529: DEBUG/MainProcess] | Worker: Starting Pool
[2015-07-08 14:15:02,645: DEBUG/MainProcess] ^-- substep ok
[2015-07-08 14:15:02,648: DEBUG/MainProcess] | Worker: Starting Consumer
[2015-07-08 14:15:02,650: DEBUG/MainProcess] | Consumer: Starting Connection
[2015-07-08 14:15:02,680: DEBUG/MainProcess] Start from server, version: 0.9, properties: {u'information': u'Licensed under the MPL.  See http://www.rabbitmq.com/', u'product': u'RabbitMQ', u'copyrigh
t': u'Copyright (C) 2007-2014 GoPivotal, Inc.', u'capabilities': {u'exchange_exchange_bindings': True, u'connection.blocked': True, u'authentication_failure_close': True, u'basic.nack': True, u'per_co
nsumer_qos': True, u'consumer_priorities': True, u'consumer_cancel_notify': True, u'publisher_confirms': True}, u'cluster_name': u'rabbit@OPHIR-PC', u'platform': u'Erlang/OTP', u'version': u'3.5.3'},
mechanisms: [u'AMQPLAIN', u'PLAIN'], locales: [u'en_US']
[2015-07-08 14:15:02,724: DEBUG/MainProcess] Open OK!
[2015-07-08 14:15:02,724: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2015-07-08 14:15:02,726: DEBUG/MainProcess] ^-- substep ok
[2015-07-08 14:15:02,726: DEBUG/MainProcess] | Consumer: Starting Events
[2015-07-08 14:15:02,762: DEBUG/MainProcess] Start from server, version: 0.9, properties: {u'information': u'Licensed under the MPL.  See http://www.rabbitmq.com/', u'product': u'RabbitMQ', u'copyrigh
t': u'Copyright (C) 2007-2014 GoPivotal, Inc.', u'capabilities': {u'exchange_exchange_bindings': True, u'connection.blocked': True, u'authentication_failure_close': True, u'basic.nack': True, u'per_co
nsumer_qos': True, u'consumer_priorities': True, u'consumer_cancel_notify': True, u'publisher_confirms': True}, u'cluster_name': u'rabbit@OPHIR-PC', u'platform': u'Erlang/OTP', u'version': u'3.5.3'},
mechanisms: [u'AMQPLAIN', u'PLAIN'], locales: [u'en_US']
[2015-07-08 14:15:02,776: DEBUG/MainProcess] Open OK!
[2015-07-08 14:15:02,778: DEBUG/MainProcess] using channel_id: 1
[2015-07-08 14:15:02,779: DEBUG/MainProcess] Channel open
[2015-07-08 14:15:02,780: DEBUG/MainProcess] ^-- substep ok
[2015-07-08 14:15:02,780: DEBUG/MainProcess] | Consumer: Starting Mingle
[2015-07-08 14:15:02,782: INFO/MainProcess] mingle: searching for neighbors
[2015-07-08 14:15:02,782: DEBUG/MainProcess] using channel_id: 1
[2015-07-08 14:15:02,790: DEBUG/MainProcess] Channel open
[2015-07-08 14:15:03,802: INFO/MainProcess] mingle: all alone
[2015-07-08 14:15:03,802: DEBUG/MainProcess] ^-- substep ok
[2015-07-08 14:15:03,803: DEBUG/MainProcess] | Consumer: Starting Tasks
[2015-07-08 14:15:03,808: DEBUG/MainProcess] ^-- substep ok
[2015-07-08 14:15:03,809: DEBUG/MainProcess] | Consumer: Starting Control
[2015-07-08 14:15:03,809: DEBUG/MainProcess] using channel_id: 2
[2015-07-08 14:15:03,811: DEBUG/MainProcess] Channel open
[2015-07-08 14:15:03,816: DEBUG/MainProcess] ^-- substep ok
[2015-07-08 14:15:03,818: DEBUG/MainProcess] | Consumer: Starting Heart
[2015-07-08 14:15:03,819: DEBUG/MainProcess] ^-- substep ok
[2015-07-08 14:15:03,819: DEBUG/MainProcess] | Consumer: Starting Gossip
[2015-07-08 14:15:03,821: DEBUG/MainProcess] using channel_id: 3
[2015-07-08 14:15:03,822: DEBUG/MainProcess] Channel open
[2015-07-08 14:15:03,832: DEBUG/MainProcess] ^-- substep ok
[2015-07-08 14:15:03,832: DEBUG/MainProcess] | Consumer: Starting event loop
[2015-07-08 14:15:03,834: WARNING/MainProcess] celery@OPHIR-PC ready.
[2015-07-08 14:15:03,834: DEBUG/MainProcess] basic.qos: prefetch_count->16
[2015-07-08 14:15:03,835: INFO/MainProcess] Received task: celery_test.service.operation[f3ed8b0e-009d-4fad-8cec-1c7b1d1e5797]
[2015-07-08 14:15:03,835: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x000000000404F208> (args:('celery_test.service.operation', 'f3ed8b0e-009d-4fad-8cec-1c7b1d1e5797', ('foo',),
 {}, {'timelimit': (None, None), 'utc': True, u'is_eager': False, 'chord': None, u'group': None, 'args': ('foo',), 'retries': 0, u'delivery_info': {u'priority': None, u'redelivered': False, u'routing_
key': u'celery', u'exchange': u'celery'}, 'expires': None, u'hostname': 'celery@OPHIR-PC', 'task': 'celery_test.service.operation', 'callbacks': None, u'correlation_id': u'f3ed8b0e-009d-4fad-8cec-1c7b
1d1e5797', 'errbacks': None, u'reply_to': u'f1fa5ace-0038-3058-93da-6ed2d6b5e752', 'taskset': None, 'kwargs': {}, 'eta': None, 'id': 'f3ed8b0e-009d-4fad-8cec-1c7b1d1e5797', u'headers': {}}) kwargs:{})

[2015-07-08 14:15:03,835: INFO/Worker-1] foo
[2015-07-08 14:15:03,838: DEBUG/MainProcess] Task accepted: celery_test.service.operation[f3ed8b0e-009d-4fad-8cec-1c7b1d1e5797] pid:10188
[2015-07-08 14:15:03,839: INFO/MainProcess] Task celery_test.service.operation[f3ed8b0e-009d-4fad-8cec-1c7b1d1e5797] succeeded in 0.00399994850159s: 1
[2015-07-08 14:15:07,926: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]
[2015-07-08 14:15:07,927: INFO/MainProcess] Events of group {task} enabled by remote.
[2015-07-08 14:15:12,918: DEBUG/MainProcess] pidbox received method enable_events() [reply_to:None ticket:None]

I also tried with amqp backend, and there were no changes.

Apparently it's a known issue on windows

There's an open ticket: https://github.com/celery/celery/issues/897

And a workaround - specify pool=solo when starting the worker:

celery -A celery_test.service worker --loglevel=debug --pool=solo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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