On this page
asyncio.new_event_loop
Prev: asyncio.isfuture | Up: asyncio | Next: asyncio.open_connection
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.new_event_loop
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import new_event_loop
Signature & Overview
asyncio.new_event_loop()
Equivalent to calling get_event_loop_policy().new_event_loop().
Usage
import asyncio
loop = asyncio.new_event_loop()
try:
assert loop.run_until_complete(asyncio.sleep(0, result="ok")) == "ok"
finally:
loop.close()
Gotchas
- Always call
loop.close(): In application code, preferasyncio.run()orwith asyncio.Runner() as runner:so cleanup is automatic.
REPL Inspect
from asyncio import new_event_loop
help(new_event_loop)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/isfuture Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/open_connection 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