Execute Single and Multiple Tasks

This lesson will teach you cooperative multitasking to execute single and multiple tasks using python.

In asynchronous programming, the execution of a function is usually non-blocking. In other words, each time you call a function it returns immediately. However, that function does not necessarily get executed right away. Instead, there is usually a mechanism (called the “scheduler”) which is responsible for the future execution of the function.

The problem with asynchronous programming is that a program may end before any asynchronous function starts. A common solution for this is for asynchronous functions to return “futures” or “promises”. These are objects that represent the state of execution of an async function. Finally, asynchronous programming frameworks typically have mechanisms to block or wait for those async functions to end based on those “future” objects.

Co-operative Multitasking

Since Python 3.6, the asyncio module combined with the async and await keyword allows us to implement what is called co-operative multitasking programs. In this type of programming, a coroutine function voluntarily yields control to another coroutine function when idle or when waiting for some input.

Asynchronous functions are declared with async def.

Get hands-on with 1400+ tech skills courses.