Why am I getting NotImplementedError with async and await on Windows?

Different event loops are implemented differently. Some of them have restrictions (sometimes OS-related). By default, Windows uses SelectorEventLoop and as you can see in doc:

SelectorEventLoop has the following limitations:

  • SelectSelector is used to wait on socket events: it supports sockets and is limited to 512 sockets.
  • loop.add_reader() and loop.add_writer() only accept socket handles (e.g. pipe file descriptors are not supported).
  • Pipes are not supported, so the loop.connect_read_pipe() and loop.connect_write_pipe() methods are not implemented.
  • Subprocesses are not supported, i.e. loop.subprocess_exec() and loop.subprocess_shell() methods are not implemented.

To run your code in Windows you can use alternative event loop available by default – ProactorEventLoop.

Replace line:

loop = asyncio.get_event_loop()

with this:

loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)

Your code will work.

Leave a Comment