Commit graph

13 commits

Author SHA1 Message Date
Miss Islington (bot)
cf777399a9
[3.11] gh-111085: Fix invalid state handling in TaskGroup and Timeout (GH-111111) (GH-111172)
asyncio.TaskGroup and asyncio.Timeout classes now raise proper RuntimeError
if they are improperly used.

* When they are used without entering the context manager.
* When they are used after finishing.
* When the context manager is entered more than once (simultaneously or
  sequentially).
* If there is no current task when entering the context manager.

They now remain in a consistent state after an exception is thrown,
so subsequent operations can be performed correctly (if they are allowed).

(cherry picked from commit 6c23635f2b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-10-21 19:40:07 +00:00
Miss Islington (bot)
7e5ba351e0
gh-102560 Add docstrings to asyncio.TaskGroup (GH-102565)
(cherry picked from commit e94edab727)

Co-authored-by: JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com>
2023-03-15 00:27:33 -07:00
Miss Islington (bot)
36d25a4f7f
[3.11] GH-98543: Fix asyncio.TaskGroup to not keep reference to errors after raising ExceptionGroup (GH-98544) (#98550)
GH-98543: Fix `asyncio.TaskGroup`  to not keep reference to errors after raising ExceptionGroup  (GH-98544)
(cherry picked from commit f4a14941e6)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-10-24 11:08:22 -07:00
Miss Islington (bot)
36c114ab11
GH-95704: Don't suppress errors from tasks when TG is cancelled (GH-95761)
When a task catches CancelledError and raises some other error,
the other error should not silently be suppressed.

Any scenario where a task crashes in cleanup upon cancellation
will now result in an ExceptionGroup wrapping the crash(es)
instead of propagating CancelledError and ignoring the side errors.

NOTE: This represents a change in behavior (hence the need to
change several tests).  But it is only an edge case.

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
(cherry picked from commit f51f54f39d)

Co-authored-by: Guido van Rossum <guido@python.org>
2022-08-17 10:04:59 -07:00
Miss Islington (bot)
24dd1429e5
gh-95724: Clarify taskgroups.py license. (GH-95847)
(cherry picked from commit 7da4937748)

Co-authored-by: Yury Selivanov <yury@edgedb.com>
2022-08-11 16:45:30 -07:00
Miss Islington (bot)
2d84fe59c0
GH-95289: Always call uncancel() when parent cancellation is requested (GH-95602)
Co-authored-by: Guido van Rossum <guido@python.org>
(cherry picked from commit 2fef27589e)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2022-08-04 07:50:54 -07:00
Miss Islington (bot)
7fe949e5ea
GH-94398: TaskGroup: Fail create_task() during shutdown (GH-94400) (GH-94463)
Once the task group is shutting down, it should not be possible to create a new task.
Here "shutting down" means `self._aborting` is set, indicating that at least one task
has failed and we have cancelled all others.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 594c369949)

Co-authored-by: Guido van Rossum <guido@python.org>
2022-06-30 20:02:42 +02:00
Miss Islington (bot)
cf63b80bc4
gh-93297: Make asyncio task groups prevent child tasks from being GCed (GH-93299) (#93305)
(cherry picked from commit e6a57678ca)

Co-authored-by: Yury Selivanov <yury@edgedb.com>

Co-authored-by: Yury Selivanov <yury@edgedb.com>
2022-05-27 15:46:57 -07:00
Andrew Svetlov
9523c0d84f
bpo-46994: Accept explicit contextvars.Context in asyncio create_task() API (GH-31837) 2022-03-14 13:54:13 +02:00
Tin Tvrtković
edbee56d69
Taskgroup tweaks (GH-31559)
Now uses .cancel()/.uncancel(), for even fewer broken edge cases.
2022-02-26 08:18:48 -08:00
Andrew Svetlov
e7130c2e8c
bpo-46752: Uniform TaskGroup.__repr__ (GH-31409) 2022-02-20 12:07:00 +02:00
Guido van Rossum
d85121660e
bpo-46752: Slight improvements to TaskGroup API (GH-31398)
* Remove task group names (for now)

We're not sure that they are needed, and once in the code
we would never be able to get rid of them.

Yury wrote:

> Ideally, there should be a way for someone to build a "trace"
> of taskgroups/task leading to the current running task.
> We could do that using contextvars, but I'm not sure we should
> do that in 3.11.

* Pass optional name on to task in create_task()

* Remove a bunch of unused stuff
2022-02-17 21:30:44 -08:00
Guido van Rossum
602630ac18
bpo-46752: Add TaskGroup; add Task..cancelled(),.uncancel() (GH-31270)
asyncio/taskgroups.py is an adaptation of taskgroup.py from EdgeDb, with the following key changes:

- Allow creating new tasks as long as the last task hasn't finished
- Raise [Base]ExceptionGroup (directly) rather than TaskGroupError deriving from MultiError
- Instead of monkey-patching the parent task's cancel() method,
  add a new public API to Task

The Task class has a new internal flag, `_cancel_requested`, which is set when `.cancel()` is called successfully. The `.cancelling()` method returns the value of this flag. Further `.cancel()` calls while this flag is set return False. To reset this flag, call `.uncancel()`.

Thus, a Task that catches and ignores `CancelledError` should call `.uncancel()` if it wants to be cancellable again; until it does so, it is deemed to be busy with uninterruptible cleanup.

This new Task API helps solve the problem where TaskGroup needs to distinguish between whether the parent task being cancelled "from the outside" vs. "from inside".

Co-authored-by: Yury Selivanov <yury@edgedb.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2022-02-15 15:42:04 -08:00