Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GH-94398: TaskGroup: Fail create_task() during shutdown #94400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
eed2413
GH-94398: TaskGroup: Fail create_task() during shutdown
gvanrossum Jun 29, 2022
0453e5e
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 29, 2022
35b5645
Shorter sleep (even though it's aborted)
gvanrossum Jun 29, 2022
193623f
Use :class:`asyncio.TaskGroup` in Blurb.
ambv Jun 30, 2022
41302b0
gh-82006: IDLE doc improvements (#94349)
terryjreedy Jun 27, 2022
8699848
GH-89988: Fix memory leak in pickle.Pickler dispatch_table lookup (GH…
kumaraditya303 Jun 28, 2022
fee1b9f
gh-94208: Add more TLS version/protocol checks for FreeBSD (GH-94347)
tiran Jun 28, 2022
01f25f3
gh-86404: [doc] Fix missing space in idle documentation. (GH-94366)
JulienPalard Jun 28, 2022
4c130ea
Generalize build_msi GitHub action (GH-94201)
arhadthedev Jun 28, 2022
8603119
gh-94199: Remove hashlib.pbkdf2_hmac() Python implementation (GH-94200)
vstinner Jun 28, 2022
98082d0
gh-87995: Make MappingProxyType hashable (GH-94252)
serhiy-storchaka Jun 28, 2022
0282cf9
Add docs for decorated object and field specifier params (GH-94354)
debonte Jun 28, 2022
5e9d3b6
gh-94018: Remove trailing spaces in _sanitize_windows_name (GH-94040)
Rygone Jun 28, 2022
b5942e9
gh-61585: Clarify import scope in modules tutorial (GH-93455)
slateny Jun 28, 2022
8e1bce0
gh-94172: Remove ssl.PROTOCOL_SSLv2 dead code (#94312)
vstinner Jun 28, 2022
3daebfe
gh-93939: Create and install scripts in Makefile (GH-94324)
tiran Jun 28, 2022
7613609
gh-88116: Avoid undefined behavior when decoding varints in code obje…
pablogsal Jun 28, 2022
e2a0a60
Fix typos in comments (#94305)
yutotnh Jun 28, 2022
975a0cf
gh-94395: Remove unneeded module state from mmap (#94396)
erlend-aasland Jun 29, 2022
bf43498
gh-94404: makesetup: use correct CFLAGS and macOS workaround (GH-94405)
tiran Jun 29, 2022
2e919ba
gh-94026: Buffer regrtest worker stdout in temporary file (GH-94253)
tiran Jun 29, 2022
3fa27d3
gh-86404: [doc] Two 'make suspicious' false positives. (GH-94407)
JulienPalard Jun 29, 2022
1479a39
gh-94401: Remove unneeded overlapped module state (#94403)
Jun 29, 2022
6e77150
gh-94404: Use module CFLAGS before PY_STDMODULE_CFLAGS (GH-94413)
tiran Jun 29, 2022
c172b62
Delete unused PC/empty.c (GH-94418)
arhadthedev Jun 29, 2022
26a62e4
gh-94401: Remove unneeded bz2 module state (#94402)
Jun 29, 2022
be02d89
Docs: Update SyntaxError message in REPL example for list comprehensi…
csabella Jun 29, 2022
6a6b87d
bpo-92336: [doc] clarify that the dfile is read by the traceback disp…
iritkatriel Jun 29, 2022
9771d0a
gh-92336: linecache.getline should not raise exceptions on decoding e…
iritkatriel Jun 30, 2022
b966d66
gh-94332: make it safe to call assemble_free when assemble_init has n…
iritkatriel Jun 30, 2022
25c5af5
Delete DOS-only PC/testpy.py (GH-94419)
arhadthedev Jun 30, 2022
2d55fea
GH-94329: Don't raise on excessive stack consumption (GH-94421)
markshannon Jun 30, 2022
6a5a45f
gh-89038: [doc] update dis.findlinestarts documentation for changes r…
iritkatriel Jun 30, 2022
c9920dd
gh-91719: Reload opcode on unknown error so that C can optimize the d…
neonene Jun 30, 2022
9eb94f3
gh-93491: Fix PEP 11 tier detection for FreeBSD (GH-94441)
tiran Jun 30, 2022
159a057
GH-90908: Document asyncio.TaskGroup (GH-94359)
gvanrossum Jun 30, 2022
5b9817d
Document the new behavior
gvanrossum Jun 30, 2022
32cfb35
Merge branch 'main' into task-group-abort
gvanrossum Jun 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ no new tasks may be added to the group.
The first time any of the tasks belonging to the group fails
with an exception other than :exc:`asyncio.CancelledError`,
the remaining tasks in the group are cancelled.
No further tasks can then be added to the group.
At this point, if the body of the ``async with`` statement is still active
(i.e., :meth:`~object.__aexit__` hasn't been called yet),
the task directly containing the ``async with`` statement is also cancelled.
Expand Down
2 changes: 2 additions & 0 deletions Lib/asyncio/taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def create_task(self, coro, *, name=None, context=None):
raise RuntimeError(f"TaskGroup {self!r} has not been entered")
if self._exiting and not self._tasks:
raise RuntimeError(f"TaskGroup {self!r} is finished")
if self._aborting:
raise RuntimeError(f"TaskGroup {self!r} is shutting down")
if context is None:
task = self._loop.create_task(coro)
else:
Expand Down
27 changes: 23 additions & 4 deletions Lib/test/test_asyncio/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ async def runner():
self.assertTrue(t2.cancelled())

async def test_cancel_children_on_child_error(self):
"""
When a child task raises an error, the rest of the children
are cancelled and the errors are gathered into an EG.
"""
# When a child task raises an error, the rest of the children
# are cancelled and the errors are gathered into an EG.

NUM = 0
t2_cancel = False
Expand Down Expand Up @@ -722,6 +720,27 @@ async def coro(val):
await t2
self.assertEqual(2, ctx.get(cvar))

async def test_taskgroup_no_create_task_after_failure(self):
async def coro1():
await asyncio.sleep(0.001)
1 / 0
async def coro2(g):
try:
await asyncio.sleep(1)
except asyncio.CancelledError:
with self.assertRaises(RuntimeError):
g.create_task(c1 := coro1())
# We still have to await c1 to avoid a warning
with self.assertRaises(ZeroDivisionError):
await c1

with self.assertRaises(ExceptionGroup) as cm:
async with taskgroups.TaskGroup() as g:
g.create_task(coro1())
g.create_task(coro2(g))

self.assertEqual(get_error_types(cm.exception), {ZeroDivisionError})


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Once a :class:`asyncio.TaskGroup` has started shutting down (i.e., at least one task has failed and the task group has started cancelling the remaining tasks), it should not be possible to add new tasks to the task group.