async io tasks async def do_something()print('do_something create task for worker'task asyncio create_task(worker()print('do_something add callback'task add_done_callback(print_itawait task information on task print('do_something task cancelled():'task cancelled()print('do_something task done():'task done()print('do_something task result():'task result()print('do_something task exception():'task exception()print('do_something finished'def main(print('main starting'asyncio run(do_something()print('main done'if __name__ ='__main__'main(in this examplethe worker(function is wrapped within task object that is returned from the asyncio create_task(worker()call function (print_it()is registered as callback on the task using the asyncio create_task(worker()function note that the worker is passed the task that has completed as parameter this allows it to obtain information from the task such as any result generated in this example the async function do_something(explicitly waits on the task to complete once this happens several different methods are used to obtain information about the task (such as whether it was cancelled or notone other point to note about this listing is that in the worker(function we have added an await using the asyncio sleep( functionthis allows the worker to sleep and wait for the triggered task to completeit is an async io alternative to time sleep( the output from this program ismain starting do_something create task for worker do_something add callback worker will take some time worker done it print_it result do_something task cancelled()false do_something task done()true do_something task result() do_something task exception()none do_something finished main done