Asyncio
asyncio คือ library สำหรับ asynchronous programming ใน Python ใช้สำหรับ I/O-bound และ high-level structured network code
ทำความเข้าใจ Async
Section titled “ทำความเข้าใจ Async”# Synchronous vs Asynchronous
# Synchronous: รอจบก่อนไปต่อprint("Synchronous flow:")print(" 1. Start task A")print(" 2. Wait for A to complete")print(" 3. Start task B")print(" 4. Wait for B to complete")print(" 5. Done")
# Asynchronous: ไม่ต้องรอ สลับไปทำอย่างอื่นได้print("\nAsynchronous flow:")print(" 1. Start task A")print(" 2. While A is waiting (I/O), switch to B")print(" 3. Continue B")print(" 4. A finished, continue A")print(" 5. Done (faster!)")
# เหมาะกับงาน I/O-boundprint("\nBest for:")print(" - Network requests")print(" - File I/O")print(" - Database queries")เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google