asyncio+aiohttp出现Exception ignored:RuntimeError('Event loop is closed')

2022/6/26 23:27:08

本文主要是介绍asyncio+aiohttp出现Exception ignored:RuntimeError('Event loop is closed'),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、报错信息

 1 Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001B11653EF70>
 2 Traceback (most recent call last):
 3   File "D:\Codes\SpiderProject\BingImageSpider\demo.py", line 16, in wrappers
 4     return func(self, *args, **kwargs)
 5   File "D:\DevTools\Python\lib\asyncio\proactor_events.py", line 116, in __del__
 6     self.close()
 7   File "D:\DevTools\Python\lib\asyncio\proactor_events.py", line 108, in close
 8     self._loop.call_soon(self._call_connection_lost, None)
 9   File "D:\DevTools\Python\lib\asyncio\base_events.py", line 746, in call_soon
10     self._check_closed()
11   File "D:\DevTools\Python\lib\asyncio\base_events.py", line 510, in _check_closed
12     raise RuntimeError('Event loop is closed')
13 RuntimeError: Event loop is closed

 

二、原因分析

像 aiohttp 这类第三方协程库都是依赖于标准库 asyncio 的,而 asyncio 对 Windows 的支持本来就不好。Python3.8 后默认 Windows 系统上的事件循环采用 ProactorEventLoop (仅用于 Windows )这篇文档描述了其在 Windows 下的缺陷:https://docs.python.org/zh-cn/3/library/asyncio-platforms.html#windows 



这篇关于asyncio+aiohttp出现Exception ignored:RuntimeError('Event loop is closed')的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程