Monitor file for read availability using asyncio on Windows

161 views Asked by At

Using asyncio's add_reader() method on Unix systems, I can easily monitor file descriptors, such as pipes, for read availability and invoke a callback once the file is available for reading.

For example, if I have two processes connected via a pipe, I'd like to invoke a callback as soon as there is data available in the pipe for reading. The code below works fine on Unix systems:

loop = asyncio.get_running_loop()
loop.add_reader(my_pipe.fileno(), my_callback)

However, since Windows does not support the add_reader method with pipes (only sockets are supported when using the SelectorEventLoop), is there an efficient workaround to achieve the same behavior using only asyncio? If not, what would be a good way to go about it?

0

There are 0 answers