Tornado executes asyncio asyncio error RUN_FOREVER assert self._SELF_READING_FUTURE IS None
Error message: python38\lib\asyncio\windows_events.py”, line 314 RUN_forever assert self._SELF_READING_future is None
The solution is as follows:
Nest_asyncio needs to be introduced. The code is as follows:
import nest_asyncio
nest_asyncio.apply()
Encapsulates executing multiple asynchronous methods and returning results
import asyncio
import nest_asyncio
from tornado.platform.asyncio import to_asyncio_future
nest_asyncio.apply()
async def asyncio_all_task(*fuc_list):
' ' '
Execute multiple asynchronous methods
' ' '
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