On this page
asyncio.set_event_loop
Prev: asyncio.run_coroutine_threadsafe | Up: asyncio | Next: asyncio.set_event_loop_policy
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.set_event_loop
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import set_event_loop
Signature & Overview
asyncio.set_event_loop(loop)
Equivalent to calling get_event_loop_policy().set_event_loop(loop).
Usage
import asyncio
# Legacy API for binding a loop to the current thread; prefer asyncio.run()
assert callable(asyncio.set_event_loop)
Gotchas
- Rarely needed in modern Python:
asyncio.run()andasyncio.Runnermanage thread loop binding automatically.
REPL Inspect
from asyncio import set_event_loop
help(set_event_loop)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/run_coroutine_threadsafe Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/set_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