Lab 06: Async Internals
Overview
Step 1: The Event Loop Internals
import asyncio
import selectors
# Get the current event loop
loop = asyncio.new_event_loop()
print(f"Event loop type: {type(loop).__name__}")
print(f"Selector: {type(loop._selector).__name__}")
# _ready queue: callbacks to execute in next iteration
print(f"Ready queue: {loop._ready}")
# _scheduled: future callbacks (heapq by time)
print(f"Scheduled queue: {loop._scheduled}")
loop.close()Step 2: selectors — I/O Multiplexing
selectors — I/O MultiplexingStep 3: asyncio.Future Internals
asyncio.Future InternalsStep 4: Task Scheduling and Execution Order
Step 5: loop.call_soon vs loop.call_later vs loop.call_at
loop.call_soon vs loop.call_later vs loop.call_atStep 6: Async Generators
Step 7: contextvars.ContextVar — Request-Scoped State
contextvars.ContextVar — Request-Scoped StateStep 8: Capstone — Mini Event Loop
Summary
Concept
API
Use Case
Last updated
