@@ -319,18 +319,18 @@ Task
319
319
Schedule the execution of a :ref: `coroutine <coroutine >`: wrap it in a
320
320
future. A task is a subclass of :class: `Future `.
321
321
322
- A task is responsible to execute a coroutine object in an event loop. If
322
+ A task is responsible for executing a coroutine object in an event loop. If
323
323
the wrapped coroutine yields from a future, the task suspends the execution
324
324
of the wrapped coroutine and waits for the completition of the future. When
325
325
the future is done, the execution of the wrapped coroutine restarts with the
326
326
result or the exception of the future.
327
327
328
328
Event loops use cooperative scheduling: an event loop only runs one task at
329
- the same time. Other tasks may run in parallel if other event loops are
329
+ a time. Other tasks may run in parallel if other event loops are
330
330
running in different threads. While a task waits for the completion of a
331
331
future, the event loop executes a new task.
332
332
333
- The cancellation of a task is different than cancelling a future. Calling
333
+ The cancellation of a task is different from the cancelation of a future. Calling
334
334
:meth: `cancel ` will throw a :exc: `~concurrent.futures.CancelledError ` to the
335
335
wrapped coroutine. :meth: `~Future.cancelled ` only returns ``True `` if the
336
336
wrapped coroutine did not catch the
341
341
<coroutine>` did not complete. It is probably a bug and a warning is
342
342
logged: see :ref: `Pending task destroyed <asyncio-pending-task-destroyed >`.
343
343
344
- Don't create directly :class: `Task ` instances: use the :func: `async `
344
+ Don't directly create :class: `Task ` instances: use the :func: `async `
345
345
function or the :meth: `BaseEventLoop.create_task ` method.
346
346
347
347
.. classmethod :: all_tasks(loop=None)
@@ -360,17 +360,17 @@ Task
360
360
361
361
.. method :: cancel()
362
362
363
- Request this task to cancel itself.
363
+ Request that this task cancel itself.
364
364
365
365
This arranges for a :exc: `~concurrent.futures.CancelledError ` to be
366
366
thrown into the wrapped coroutine on the next cycle through the event
367
367
loop. The coroutine then has a chance to clean up or even deny the
368
368
request using try/except/finally.
369
369
370
- Contrary to :meth: `Future.cancel `, this does not guarantee that the task
370
+ Unlike :meth: `Future.cancel `, this does not guarantee that the task
371
371
will be cancelled: the exception might be caught and acted upon, delaying
372
- cancellation of the task or preventing it completely. The task may also
373
- return a value or raise a different exception.
372
+ cancellation of the task or preventing cancellation completely. The task
373
+ may also return a value or raise a different exception.
374
374
375
375
Immediately after this method is called, :meth: `~Future.cancelled ` will
376
376
not return ``True `` (unless the task was already cancelled). A task will
405
405
This produces output similar to that of the traceback module, for the
406
406
frames retrieved by get_stack(). The limit argument is passed to
407
407
get_stack(). The file argument is an I/O stream to which the output
408
- goes ; by default it goes to sys.stderr.
408
+ is written ; by default output is written to sys.stderr.
409
409
410
410
411
411
Example: Parallel execution of tasks
0 commit comments