Tag: asyncio
9 รายการ
Blog
Python AsyncContextDecorator: ใช้ lifecycle เดียวกันทั้ง async with และ decorator
สร้างขอบเขต async ที่นำกลับใช้ได้สองรูปแบบ พร้อม unittest พิสูจน์ลำดับ enter/work/exit
Python AsyncExitStack: รวม cleanup แบบ sync และ async ไว้ในจุดเดียว
จัดการ resource ที่เปิดตามเงื่อนไขด้วย contextlib.AsyncExitStack และยืนยันลำดับปิดย้อนกลับด้วย unittest
Python 3.15: TaskGroup.cancel — ยกเลิกกลุ่มงาน asyncio แบบตรง ๆ
สรุป asyncio.TaskGroup.cancel ใน Python 3.15 — เลิกใช้ทริคยก exception ปลอมเพื่อหยุดกลุ่มเมื่องานเสร็จก่อนกำหนด
asyncio.print_call_graph: ดูต้นไม้ task ค้างตอนดีบัก (Python 3.14)
ใช้ capture_call_graph / print_call_graph / format_call_graph ดูว่าคอร์รูทีนไหนรออะไร พร้อมตัวอย่าง static ที่รันบน 3.14
Python contextlib.aclosing: ปิด Async Generator แม้ Loop หยุดก่อนจบ
ใช้ aclosing จัด lifecycle ของ async generator ให้ cleanup รันใน context เดิม พร้อม unittest ที่พิสูจน์กรณี break กลาง stream
asyncio.Queue.shutdown: ปิดสายพานงานโดยไม่ส่ง Sentinel
ใช้ shutdown และ QueueShutDown แยกการปิดรับงานออกจากการประมวลผลงานค้าง พร้อมทดสอบ graceful shutdown จริง

asyncio.timeout: ใส่กรอบเวลาให้งาน async โดยไม่กลืน CancelledError
ใช้ asyncio.timeout เป็น context manager จำกัดเวลารอ พร้อม unittest.IsolatedAsyncioTestCase ที่พิสูจน์ทั้งสำเร็จและ TimeoutError
Python contextvars: ส่ง Request ID ข้าม async โดยไม่ปนกัน
ใช้ ContextVar แทน global สำหรับข้อมูลระดับ task พร้อม unittest ที่ปล่อยสอง coroutine วิ่งพร้อมกัน
Python asyncio.TaskGroup: ให้งานพี่น้องล้มและยกเลิกเป็นกลุ่ม
ใช้ structured concurrency ใน Python เพื่อไม่ทิ้ง background task ค้าง พร้อม unittest ที่ทดสอบทั้งสำเร็จและ fail-fast