5

What exactly are SelectorEventLoop and ProactorEventLoop? How are they different?

I was testing the use of asyncio and aiohttp in python on Windows, then got an error RuntimeError: Event loop is closed. Looked up and found a workaround, but I did not understand the root of the error.
Many people seem to touch on the concept of SelectorEventLoop and ProactorEventLoop here and also here.

I read documentation but couldn't grasp the concept. Could anyone explain these concept in easier terms?

koyamashinji
  • 535
  • 1
  • 6
  • 19
  • 4
    In short: Windows uses [I/O Completion Ports](https://docs.microsoft.com/en-us/windows/win32/fileio/i-o-completion-ports) for processing multiple async IO operations (not to go in-depth, Windows implements things differently at a "deeper" level (for lack of better words), and to access different IO asynchronously you *must* use this interface). Therefore, two implementations were made: `SelectorEventLoop`, which is the default for most platforms (MacOS, Linux, etc.), and `ProactorEventLoop`, which is the Windows-specific event-loop that is capable of making IO bound calls on Windows machines. – felipe Jun 14 '21 at 03:49
  • 3
    Note that `SelectorEventLoop` still works on Windows, but only works with sockets, and not pipes. Since pipes are a process communication tool it requires more in-depth kernel-level implementations, and on Windows, it is named "I/O Completion Ports", which is what `ProactorEventLoop` uses. – felipe Jun 14 '21 at 03:55
  • More details about differences: https://docs.python.org/3.8/library/asyncio-platforms.html#windows – T.Todua Aug 18 '22 at 09:19

0 Answers0