Search code examples
pythonwindowsasynchronousselectio

How to perform I/O multiplexing on non-socket FDs in Windows? (Python)


I'm writing an async framework in Python, you may check that out here on GitHub. I have successfully implemented the basic functionality and now I need to make file I/O and hopefully make it cross-platform. I know that windows cannot handle streams that do not originate from WinSock (I'm using python's selectors module as it has a higher-level API). I know that libraries such as trio or curio can perform such async file I/O on any platform. I wonder, how may I implement such a functionality?


Solution

  • Everyone does it by spawning background threads that use blocking I/O internally. The native async I/O support is just so broken and different on each OS that using threads and normal I/O is the only feasible option. Not even Linux gets it right. See the comment by njsmith https://github.com/python-trio/trio/issues/20#issuecomment-306107585