Tornado IOLoop Exception in callback None in Celery worker

空扰寡人 提交于 2019-12-06 15:30:58

This looks like a threading problem. I'm not familiar with celery's threading model but it looks like it's starting multiple copies of CeleryWorker, each of which is trying to run the same singleton IOLoop.instance(). Each worker thread needs its own IOLoop if you're going to run it like this - look at what the synchronous tornado.httpclient.HTTPClient does to create and run a temporary IOLoop

Looks like your worker task just return and being treated as finished before ioloop stops, so gen.engine's callback cannot find the original stack_context I guess.

@task(name="MyWorker",base=WorkerBase)
def CeleryWorker(args):
    # This works because i'm adding base as WorkerBase
    CeleryWorker.RunMyTask(args)
    IOLoop.instance().start()
    return True

I have some suggestion for you

1) remove return

@task(name="MyWorker",base=WorkerBase)
def CeleryWorker(args):
    # This works because i'm adding base as WorkerBase
    CeleryWorker.RunMyTask(args)
    IOLoop.instance().start()

2) use run_sync

import functools

@task(name="MyWorker",base=WorkerBase)
def CeleryWorker(args):
    # This works because i'm adding base as WorkerBase
    func = functools.partial(CeleryWorker.RunMyTask, args)
    IOLoop.instance().run_sync(func)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!