Lesson 022: asyncio tasks, gathers, and backoff
Focus
Anchor one invariant before you branch mentally: Advanced drills asyncio tasks, gathers, and backoff; spin token 243651 makes this page unlike its neighbours.
Key ideas
- Angle
Advanced: micro cadence2mixesasyncio tasks, gathers, and backoff; spin31885. - Ritual: Sketch control flow as ASCII before trusting output.
- Guardrail: separate demo-trick from shipping discipline verbally.
Example (LESSON_UID = "advanced-022")
# Advanced drill L022 topic-2 micro-1 pattern-12
LESSON_UID = "advanced-022"
spin_a, spin_b, spin_c = 949, 391, 444
from io import StringIO
buf = StringIO()
rounds = 3 + 1 % 5
for idx in range(rounds):
buf.write(f"seg-{idx}-{(idx * 22 + spin_b) % 997}\n")
buf.seek(0)
dump = buf.read()
print("lines", dump.count("\n"))
print("peek", dump.splitlines()[0] if dump else "<empty>")
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-22.txt"
snap = [35, 989, 952, 915]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (444 + 131))
import asyncio
async def finalize(seed, spin):
await asyncio.sleep(0)
blend = (seed * 131 + 2 * (2 % 997) + 1 * (1 % 853) + spin) % 900001
return blend
async def harness(loop_seed):
print("async_result", await finalize(loop_seed, 4509))
asyncio.run(harness(19408))
Practice
Practice 35: Shadow one variable purposely to spotlight scope quirks. Literal nudge 35.
Fingerprints
- lesson_uid:
advanced-022 - umbrella band:
asyncio tasks, gathers, and backoff(2/10) - lesson_index:
680