Async

What is it ?

Is a concurrent programming pattern.

How does it work in Python?

The SO manages all the multi-tasking work.

In CPython, the GIL (Global Interpreter Lock) stops concurrency by using multiple cores - the interpreter is locked to one core.

Asyncio:

  • Without SO intervention.

  • One process, one thread.

How to support Async?

Async functions need the power to suppress and resume.

The power to suppress a function for a time period when it should be suspended and only resume it when the wait has ended.

Implementing suppression/resume in Python requires:

  • Callback's.

  • Generators.

  • Async/Await (Python 3.5+).

Asynchronous tasks programming

Async frameworks need a scheduler, usually called an "event loop".

The loop takes care of all tasks in execution.

When a function is suppressed, it returns power to the loop which is looking for another function that succeeds it.

All of this is called "cooperative multi-tasking".

Last updated