concurrency with asyncio asyncio create_task()asyncio gather(and asyncio as_completed(these additional task creation functions are described belowasyncio create_task(this function takes function marked with async and wraps it inside task and schedules it for execution by the async io event loop this function was added in python asyncio gather(*awsthis function runs all the async functions passed to it as separate tasks it gathers the results of each separate task together and returns them as list the order of the results corresponds to the order of the async functions in the aws list asyncio as_completed(awsruns each of the async functions passed to it task object supports several useful methods cancel(cancels running task calling this method will cause the task to throw cancellederror exception cancelled(returns true if the task has been cancelled done(returns true if the task has completedraised an exception or was cancelled result(returns the result of the task if it is done if the tasks result is not yet availablethen the method raises the invalidstateerror exception exception(return an exception if one was raised by the task if the task was cancelled then raises the cancellederror exception if the task is not yet donethen raises an invalidstateerror exception it is also possible to add callback function to invoke once the task has completed (or to remove such function if it has been added)add_done_callback(callbackadd callback to be run when the task is done remove_done_callback(callbackremove callback from the callbacks list note that the method is called 'addrather than 'setimplying that there can be multiple functions called when the task has completed (if requiredthe following example illustrates some of the aboveimport asyncio async def worker()print('worker will take some time'await asyncio sleep( print('worker done it'return def print_it(task)print('print_it result:'task result()