python system_error ai_generated true

运行时错误:Windows不支持add_reader()

RuntimeError: add_reader() is not supported on Windows

ID: python/asyncio-loop-add-reader

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-09-01首次发现

版本兼容性

版本状态引入弃用备注
3.7 active
3.8 active

根因分析

在Windows上使用asyncio.add_reader()或add_writer(),因为Windows默认使用ProactorEventLoop。

English

Using asyncio.add_reader() or add_writer() on Windows, which uses ProactorEventLoop by default.

generic

解决方案

  1. 90% 成功率
    reader, writer = await asyncio.open_connection(host, port)
  2. 95% 成功率
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

无效尝试

常见但无效的做法:

  1. 90% 失败

    Same issue; the loop type is still Proactor.

  2. 30% 失败

    Works but may have other limitations on Windows.