Python Glossary Русский

Python 3.13+Async programmingterm

asyncio.EventLoop

event loop

An alias for the most efficient event loop on the current OS: SelectorEventLoop on Unix and ProactorEventLoop on Windows. Added in Python 3.13.

Syntax

asyncio.run(main(), loop_factory=asyncio.EventLoop)

It is not a new loop but a name for what asyncio.run() already creates by default; on Linux asyncio.EventLoop is asyncio.SelectorEventLoop is True. You need it where the loop is passed explicitly — asyncio.run(main(), loop_factory=asyncio.EventLoop) or asyncio.Runner(loop_factory=...) — and it replaces fiddling with event loop policies, deprecated since 3.14. Python 3.11 and 3.12 lack the name: AttributeError.

Examples

import asyncio
async def main():
    await asyncio.sleep(0.01)
    return type(asyncio.get_running_loop()).__name__
name = asyncio.run(main(), loop_factory=asyncio.EventLoop)
print(name)  # → ? SelectorEventLoop на Linux и macOS, ProactorEventLoop на Windows
print(issubclass(asyncio.EventLoop, asyncio.AbstractEventLoop))  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy