python system_error ai_generated true

RuntimeError: add_reader() is not supported on Windows

ID: python/asyncio-loop-add-reader

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-09-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.7 active
3.8 active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Same issue; the loop type is still Proactor.

  2. 30% fail

    Works but may have other limitations on Windows.