【发布时间】:2017-01-11 15:07:31
【问题描述】:
我正在尝试在我的 Django 后期处理中使用 asyncio,例如:
query : # a query to my model
tasks = []
for record in query:
tasks.append(do_something_with_google_calendar(record))
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
但我只是在执行时遇到错误:
loop = asyncio.get_event_loop()
RuntimeError: There is no current event loop in thread 'Thread-17'.
有什么想法吗?
提前谢谢你
【问题讨论】:
-
do_something_with_google_calendar(record)方法是如何定义的
-
@asyncio.coroutine def do_something_with_google_calendar(args):
-
为什么不使用Celery 之类的东西进行后期处理? AsyncIO 不是用于后处理,而是用于非阻塞 IO。
-
我开始意识到这一点。
-
我认为我可以设法以异步方式访问 Google Calendar。我使用 pythonanywhere 服务器。我不能在那里使用 Celery。我可能不得不换一个新的服务器。
标签: python django multithreading loops python-asyncio