Talks - Joongi Kim: Improving debuggability of complex asyncio applications

Improve debuggability of complex asyncio applications by understanding its limitations, using the right libraries, and leveraging tools like time module, _syncio library, and STEP debugger to inspect and control execution.

Key takeaways
  • Improving debuggability of asyncio applications starts by understanding the basics of asyncio and its limitations.
  • Coroutines and tasks in asyncio are inherently lightweight and should be used to handle I/O-bound tasks, not CPU-intensive tasks.
  • Using libraries like trio and curio can simplify development and improve performance.
  • async/await syntax can help write more readable and synchronous-like code, but should be used with caution due to the overhead of switching between the event loop and the CPU.
  • To debug asyncio applications, use tools like the time module, _syncio library, and STEP debugger to inspect and control the execution of coroutines and tasks.
  • When debugging asyncio applications, use a narrowed exception message and inspect the stack trace to identify the problematic code.
  • If using libraries like async_timeout or aiosmtpd, ensure that they are configured correctly and do not interfere with the event loop.
  • When using pytest in a Jupyter notebook, use the pytest-asyncio library to properly run and test asyncio tests.
  • To improve the performance of asyncio applications, use a profiler like line_profiler or snakeviz to identify performance bottlenecks and optimize the code.
  • To reduce the risk of memory leaks in asyncio applications, use tools like mypy and pytest to identify potential issues before they become a problem.