Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit070993b

Browse files
[3.14]gh-135729: Store reference to globals inInterpreter._decref (GH-139104) (GH-139112)
*gh-135729: Store reference to globals in `Interpreter._decref` (GH-139104)(cherry picked from commit571210b)Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent5b64b59 commit070993b

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

‎Lib/concurrent/interpreters/__init__.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ def __del__(self):
149149
def__reduce__(self):
150150
return (type(self), (self._id,))
151151

152-
def_decref(self):
152+
# gh-135729: Globals might be destroyed by the time this is called, so we
153+
# need to keep references ourself
154+
def_decref(self,*,
155+
InterpreterNotFoundError=InterpreterNotFoundError,
156+
_interp_decref=_interpreters.decref,
157+
):
153158
ifnotself._ownsref:
154159
return
155160
self._ownsref=False
156161
try:
157-
_interpreters.decref(self._id)
162+
_interp_decref(self._id)
158163
exceptInterpreterNotFoundError:
159164
pass
160165

‎Lib/test/test_interpreters/test_api.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,21 @@ def test_pickle(self):
419419
unpickled=pickle.loads(data)
420420
self.assertEqual(unpickled,interp)
421421

422+
@support.requires_subprocess()
423+
@force_not_colorized
424+
deftest_cleanup_in_repl(self):
425+
# GH-135729: Using a subinterpreter in the REPL would lead to an unraisable
426+
# exception during finalization
427+
repl=script_helper.spawn_python("-i")
428+
script=b"""if True:
429+
from concurrent import interpreters
430+
interpreters.create()
431+
exit()"""
432+
stdout,stderr=repl.communicate(script)
433+
self.assertIsNone(stderr)
434+
self.assertNotIn(b"Traceback",stdout)
435+
436+
422437

423438
classTestInterpreterIsRunning(TestBase):
424439

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix unraisable exception during finalization when using
2+
:mod:`concurrent.interpreters` in the REPL.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp