我已经做了一个应用程序,它等待一个任务很快运行,但不等待得到结果,但我注意到有时
asyncio.run_coroutine_threadsafe
确实跳过了一些任务,而且它不按顺序随机运行
我将其与覆盖uwsgi的烧瓶集成(进程=1,线程=10)
run_coroutine_threadsafe
可以同时被任何线程调用
# get asyncio event loop
loop = asyncio.get_event_loop()
# define function to run in a thread
def InitAsyncio(loop):
asyncio.set_event_loop(loop)
loop.run_forever()
# create asyncio to run in thread
t = threading.Thread(target=InitAsyncio, args=(loop,))
t.start()
async def ProcessPicture(InputInt):
try:
print("This is a book. %d" % InputInt)
return
except:
return
def main():
for i in range(1000):
asyncio.run_coroutine_threadsafe(ProcessPicture(i), loop)
如何确保asyncio.run_coroutine_threadsafe
始终以不跳过的方式运行并命令任务运行
目前没有回答
相关问题 更多 >
编程相关推荐