python
system_error
ai_generated
true
运行时错误:Windows不支持add_reader()
RuntimeError: add_reader() is not supported on Windows
ID: python/asyncio-loop-add-reader
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.
解决方案
-
90% 成功率
reader, writer = await asyncio.open_connection(host, port)
-
95% 成功率
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
无效尝试
常见但无效的做法:
-
90% 失败
Same issue; the loop type is still Proactor.
-
30% 失败
Works but may have other limitations on Windows.