在执行tornado asyncio时,如何确保run_forever后self._self_reading_future为None?

2026-05-16 08:261阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计217个文字,预计阅读时间需要1分钟。

在执行tornado asyncio时,如何确保run_forever后self._self_reading_future为None?

错误信息:python38\lib\asyncio\windows_events.py,line 314,run_forever assert self._self_reading_future is None 解决方法:需要引入 nest_asyncio,代码如下:import nest_asyncio; nest_asyncio.apply() 封装执行多个异步操作

报错信息:python38\lib\asyncio\windows_events.py", line 314 run_forever assert self._self_reading_future is None

解决如下:

需要引入nest_asyncio,代码如下:

import nest_asyncio

nest_asyncio.apply()

在执行tornado asyncio时,如何确保run_forever后self._self_reading_future为None?

封装执行多个异步方法并返回结果​

import asyncio
import nest_asyncio
from tornado.platform.asyncio import to_asyncio_future

nest_asyncio.apply()

async def asyncio_all_task(*fuc_list):
'''
执行多个异步方法
'''
tasks=[]
for t in fuc_list:
tasks.append(asyncio.ensure_future(t))

result= asyncio.get_event_loop().run_until_complete(to_asyncio_future(asyncio.gather(*tasks)))
# asyncio.get_event_loop().run_until_complete(asyncio.wait(tasks))
return result

def asyncio_all_task2(*fuc_list):
result=[]
loop = asyncio.get_event_loop()
res= loop.run_until_complete(asyncio.wait(fuc_list))
for r in res[0]:
result.append(r._result)

return result

本文共计217个文字,预计阅读时间需要1分钟。

在执行tornado asyncio时,如何确保run_forever后self._self_reading_future为None?

错误信息:python38\lib\asyncio\windows_events.py,line 314,run_forever assert self._self_reading_future is None 解决方法:需要引入 nest_asyncio,代码如下:import nest_asyncio; nest_asyncio.apply() 封装执行多个异步操作

报错信息:python38\lib\asyncio\windows_events.py", line 314 run_forever assert self._self_reading_future is None

解决如下:

需要引入nest_asyncio,代码如下:

import nest_asyncio

nest_asyncio.apply()

在执行tornado asyncio时,如何确保run_forever后self._self_reading_future为None?

封装执行多个异步方法并返回结果​

import asyncio
import nest_asyncio
from tornado.platform.asyncio import to_asyncio_future

nest_asyncio.apply()

async def asyncio_all_task(*fuc_list):
'''
执行多个异步方法
'''
tasks=[]
for t in fuc_list:
tasks.append(asyncio.ensure_future(t))

result= asyncio.get_event_loop().run_until_complete(to_asyncio_future(asyncio.gather(*tasks)))
# asyncio.get_event_loop().run_until_complete(asyncio.wait(tasks))
return result

def asyncio_all_task2(*fuc_list):
result=[]
loop = asyncio.get_event_loop()
res= loop.run_until_complete(asyncio.wait(fuc_list))
for r in res[0]:
result.append(r._result)

return result