0

In the Python documentation it describes how to start and use coroutines.

This section describes how to use a Task.

In the Task section, it states:

Tasks are used to schedule coroutines concurrently

I'm failing to understand, what is happening when I start a coroutines without using Task? Is the code running asynchronously but not concurrently? Does it mean when the code sees an await it goes and does something else?

When I use a Task is it like start two threads and calling join()? I start two or more tasks and wait for the result, correct?

1 Answers1

0

For simple cases, creating Tasks manually is somewhat similar to threads – you can create them, event loop will eventually run them, and you should eventually get result/exception.

But in most cases, your code is built around await coro() – nothing low-level. This means that your code may do some I/O operation inside coro, so process is free to put your implicitly created task into queue, and resume execution later.

Slam
  • 8,112
  • 1
  • 36
  • 44