Repository navigation
Avoid cancellation checkpoint after temporary directory creation - #1403
Conversation
Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
|
Returning the name directly without |
|
I checked this on asyncio and Trio (Python 3.12): with an already-cancelled scope, the initial The regression covers cancellation while the constructor is running. With the default |
NOTE Erasing or replacing the contents of this template will result in your pull
request being summarily closed without consideration!
Changes
No linked issue.
Avoid a cancellation checkpoint between creating a temporary directory and returning from
TemporaryDirectory.__aenter__. If cancellation arrives during creation, the second worker call can raise before theasync withbody starts, so__aexit__never runs and a retained manager keeps the directory until explicit cleanup or finalization.Return the created directory's
namedirectly, matching stdlibTemporaryDirectory.__enter__, which only returns that attribute. Pending cancellation then reaches the body's checkpoint and the existing shielded__aexit__removes the directory. The regression cancels from the creation worker and keeps the manager alive.Validation on native CPython 3.12.13: the regression fails on all four backend variants on both Windows and Linux without the fix; the fixed tempfile module passes 84 tests on each platform (asyncio, winloop/uvloop, eager asyncio, Trio). Changed-file Ruff 0.16.10 checks and formatting pass on Linux. Optional Blockbuster instrumentation and the full suite were not run.
This fixes acquisition, not the explicit
cleanup()cancellation case covered by #1316. No API or documented usage changes.Checklist
If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):
tests/) which would fail without your patchdocs/), in case of behavior changes or newfeatures
changelog.d/).If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.
Updating the changelog
Add a news fragment file in the
changelog.d/directory, named<issue or PR number>.<type>.rst, where<type>is one of:breaking: backwards incompatible changesadded: new featureschanged: other user-visible changesfixed: bug fixesIf, say, your patch fixes issue #123, create
changelog.d/123.fixed.rstcontaining only a brief summary of the change, like this:
The issue link and the credit for your pull request are added automatically on release.
If there's no issue linked, name the file after your pull request instead by adding the
fragment after you've created the PR.