On this page
asyncio.Handle
Prev: asyncio.get_running_loop | Up: asyncio | Next: asyncio.IncompleteReadError
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.Handle
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import Handle
Signature & Overview
asyncio.Handle(callback, args, loop, context=None)
Object returned by callback registration methods.
Methods & Attributes
Handle.cancel(self)—Handle.cancelmethod/property.Handle.cancelled(self)—Handle.cancelledmethod/property.Handle.get_context(self)—Handle.get_contextmethod/property.
Usage
import asyncio
async def main():
loop = asyncio.get_running_loop()
called: list[str] = []
h = loop.call_soon(called.append, "ran")
assert isinstance(h, asyncio.Handle)
await asyncio.sleep(0)
assert called == ["ran"]
asyncio.run(main())
Gotchas
- Cancel pending callbacks with
h.cancel(): Returned byloop.call_soon()andloop.call_soon_threadsafe().
REPL Inspect
from asyncio import Handle
help(Handle)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/get_running_loop Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/IncompleteReadError 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