Alexander Ryzhov
Jan 9, 2025

Making the right choice between asyncio, threading and multiprocessing in Python

Consider this:

if io_bound:
    if io_very_slow:
        print("Use Asyncio")
    else:
        print("Use Threading")
else:
    print("Use Multiprocessing")
  • CPU Bound: Multiprocessing: Because each process will acquire own GIL.
  • I/O Bound, Fast I/O: Threading (limited number of connections).
  • I/O Bound, Slow I/O: Asyncio (many connections).

To my preference, python asyncio model is good for seamless working with I/O, which made it very usable in scripts. I’ve gave up on big-development in Python due to single-thread locking, weak typing and slow nature of an interpreted language. But all these drawbacks are advantages when it comes to scripting. I also understand why it’s so popular in Data Science - you can write data processing logic as fast as possible, and change it on the fly. Choose right tool for the job.