On this page
asyncio.get_event_loop
Prev: asyncio.gather | Up: asyncio | Next: asyncio.get_event_loop_policy
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.get_event_loop
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import get_event_loop
Signature & Overview
asyncio.get_event_loop()
Return an asyncio event loop.
Usage
import asyncio
async def main():
# Inside async code, prefer asyncio.get_running_loop()
assert asyncio.get_running_loop() is asyncio.get_event_loop()
asyncio.run(main())
Gotchas
- Deprecated when no loop is running: Always use
asyncio.get_running_loop()inside coroutines andasyncio.run()at the entry point.
REPL Inspect
from asyncio import get_event_loop
help(get_event_loop)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/gather Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/get_event_loop_policy Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractEventLoop Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractServer Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/all_tasks Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/as_completed Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/Barrier shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseEventLoop shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseProtocol shared tags: #asyncio, #stdlib