I have been working for a long time with asyncio in Python, however I would like to clarify some thoughts on how asyncio actually works. I will break down my thoughts so that I can give context and that you can correct me if I have any errors in the bases.I understand that Python programs are kernel-level threading model, but with GIL. So, a python program will run in a kernel process and each python will invoke an OS thread, but due to the GIL, only each of these threads will run at a time. I also understand that the only way to get multiple threads in a Python program is through the "threading" module. That is, in a normal Python program without using this module I will simply have a process with a single thread running.Then the asyncio library arrives, my question is if asyncio would be an implementation of the user-level threading model, cooperative scheduling. The event loop manages all user threads (coroutines) and each of these coroutines has a cooperative approach since through await they determine when they return control to the scheduler. Additionally, all of these user threads are mapped to a single OS thread. I am right? Is this how it works?
↧