multi-task asyncio flow control: who gets control when a nested `await' is called? #13594
-
If one has two asyncio tasks running concurrently (via gather, group, or whatever), who gets control when an Consider this very simple two-task example:
This is a VS Code example running on the PICO-W. The two tasks are complicated with many nested async/await calls. One is a bluetooth le central client communicating with health devices using aioble and the other communicates with a back end using mqtt and https. At the moment the individual tasks do not create additional tasks. Does control go to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi |
Beta Was this translation helpful? Give feedback.
-
Any runnable task can be scheduled as next task. As a good programming practice, the program logic should not rely on what task runs next. If you need a certain execution order or task priorities, that could be achieved with asyncio.Events or asyncio.Lock or by putting the code in the right order in the same task. |
Beta Was this translation helpful? Give feedback.
OK, now I understand. AFAIK asyncio scheduling is round robin. So whenever a task reaches await, the other task is scheduled, if it's not waiting,just as you describe.