Python 3.4+Async programmingterm
asyncio.SelectorEventLoop
event loop
An event loop built on the selectors module: it waits for sockets via select/epoll/kqueue. It is the default loop on Linux and macOS.
Syntax
with asyncio.Runner(loop_factory=asyncio.SelectorEventLoop) as runner: ...
You pick it explicitly in one case: Windows defaults to ProactorEventLoop, while some libraries (old database drivers, for instance) require SelectorEventLoop. The price on Windows is no subprocess support (create_subprocess_exec raises NotImplementedError) and select()'s 512-socket limit. Pass the class as a factory — asyncio.Runner(loop_factory=asyncio.SelectorEventLoop) — rather than through the deprecated event loop policies.
Examples
# Python 3.11+
import asyncio
async def main():
await asyncio.sleep(0.01)
return type(asyncio.get_running_loop()).__name__
with asyncio.Runner(loop_factory=asyncio.SelectorEventLoop) as runner:
print(runner.run(main())) # → SelectorEventLoop
See also
Open in the full glossarydocs.python.orgReport an inaccuracy