UrH*_*per 5 python python-multithreading python-3.x python-asyncio visual-studio-code
我在正确使用代码时遇到了一些困难,因为在 VSCode 上调试时我的代码完成执行后出现以下错误:
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000188AB3259D0>
Traceback (most recent call last):
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
如果我使用命令行运行代码,我也会收到以下错误:
Cancelling an overlapped future failed
future: <_OverlappedFuture pending overlapped=<pending, 0x25822633550> cb=[_ProactorReadPipeTransport._loop_reading()]>
Traceback (most recent call last):
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\windows_events.py", line 66, in _cancel_overlapped
    self._ov.cancel()
OSError: [WinError 6] The handle is invalid
下面的代码是 Reddit 的异步 API 包装器。由于 Reddit 要求将机器人限制为每分钟 60 个请求的速率,因此我决定实现一个节流循环,在单独的线程中处理队列中的请求。
要运行它,您需要创建一个 Reddit 应用程序并使用您的登录凭据以及机器人 ID 和密码。
如果有帮助,我在 Windows 10 上使用 Python 3.8.3 64 位。
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000188AB3259D0>
Traceback (most recent call last):
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "c:\users\gam3p\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
我在 asyncio 上遇到了类似的问题。
从 Python 3.8 开始,他们将 Windows 上的默认事件循环更改为 ProactorEventLoop 而不是 SelectorEventLoop,并且存在一些问题。
所以添加
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
以上
loop = asyncio.get_event_loop()
将毫无问题地恢复旧的事件循环。
| 归档时间: | 
 | 
| 查看次数: | 950 次 | 
| 最近记录: |