Hasty Briefsbeta

Bilingual

Asyncio: A library with too many sharp corners

9 months ago
  • #asyncio
  • #concurrency
  • #python
  • asyncio was introduced in Python 3.4 and became non-provisional in Python 3.5, adding async/await keywords.
  • asyncio has significant design flaws, including broken cancellation, task destruction issues, and problematic I/O handling.
  • Cancellation in asyncio is edge-triggered, leading to potential deadlocks and swallowed cancellations, unlike Trio's level-triggered approach.
  • asyncio does not keep strong references to tasks, causing tasks to be garbage collected mid-execution, leading to warnings like 'Task was destroyed but it is pending!'.
  • asyncio's I/O handling is callback-based and non-linear, making it harder to use compared to Trio's straightforward socket API.
  • asyncio.Queue lacks proper backpressure mechanisms and can lead to memory leaks or deadlocks if not managed carefully.
  • Trio and AnyIO offer better alternatives with structured concurrency, level-triggered cancellations, and more intuitive APIs.
  • Other minor issues include poor thread integration, signal handling, and task group cancellation problems in asyncio.