asyncio.get_running_loop
Prev: asyncio.get_event_loop_policy | Up: asyncio | Next: asyncio.Handle
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.get_running_loop
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import get_running_loop
Signature & Overview
asyncio.get_running_loop()
Return the running event loop. Raise a RuntimeError if there is none.
Usage
import asyncio
async def main():
loop = asyncio.get_running_loop()
assert loop.is_running()
asyncio.run(main())
Gotchas
- Preferred over
get_event_loop(): Fails fast withRuntimeErrorif called outside an active event loop instead of silently creating a new loop.
REPL Inspect
from asyncio import get_running_loop
help(get_running_loop)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/get_event_loop_policy Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/Handle 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