2

I'm implementing a celery queue-worker system, but I want to be able to call an existing library function/coroutine that is marked async. I'm getting OSErrors with loop.run_until_complete() which I assume is from trying to run event loops in a non-single threaded manner.

import asyncio
from celery import Celery

app = Celery('blah', broker='redis://localhost:6379/0')

async def async_func():
    asyncio.sleep(20)

@app.task
def task():
    # what do I do here to run async_func?
    pass
James
  • 2,742
  • 1
  • 20
  • 43
  • Oo thanks for this. `call_soon[_threadsafe]` doesn't work for me because I think the worker just moves onto the next task, and nothing blocks for the coroutine so it never gets called. I might just create another event loop for now. It feels dirty but it seems like it will work – James Oct 18 '16 at 00:35

0 Answers0