Lesson 045: Threading patterns around Queue handoffs
Focus
Prints are breadcrumbs, not ornamentation: Advanced drills Threading patterns around Queue handoffs; spin token 370845 makes this page unlike its neighbours.
Key ideas
- Angle
Advanced: micro cadence5mixesThreading patterns around Queue handoffs; spin9856. - Ritual: Add one doctest-style assertion comment above hottest print.
- Guardrail: name the surprise that triggered when literals shifted.
Example (LESSON_UID = "advanced-045")
# Advanced drill L045 topic-4 micro-4 pattern-11
LESSON_UID = "advanced-045"
spin_a, spin_b, spin_c = 193, 508, 141
bucket = dict(seed=4 + spin_a)
def tweak(offset):
local = bucket["seed"]
bucket["seed"] = local + offset
return bucket["seed"]
print(tweak(5), tweak(3), bucket)
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as scratch:
target = Path(scratch) / "scratch-45.txt"
snap = [58, 259, 460]
target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (141 + 131))
import asyncio
async def finalize(seed, spin):
await asyncio.sleep(0)
blend = (seed * 131 + 4 * (4 % 997) + 4 * (4 % 853) + spin) % 900001
return blend
async def harness(loop_seed):
print("async_result", await finalize(loop_seed, 8278))
asyncio.run(harness(48801))
Practice
Practice 24: Freeze async sleep at zero vs tiny float; articulate scheduling impact. Literal nudge 24.
Fingerprints
- lesson_uid:
advanced-045 - umbrella band:
Threading patterns around Queue handoffs(5/10) - lesson_index:
1437