一个是 asyncio run_forever (我希望它一直运行,维护一个队列)的协程函数, 用 celery 装饰成 task,这样做有效吗,代码像这样的:
import asyncio
improt celery
async def do_some_work(x):
print("Waiting " + str(x))
await asyncio.sleep(x)
def worker():
loop = asyncio.get_event_loop()
for _ in range(_concurrency):
loop.create_task(do_some_work(x))
loop.run_forever()
@app.task
def run(msg):
worker()