mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-135729: Store reference to globals in Interpreter._decref (GH-139104) (GH-139112)
* gh-135729: Store reference to globals in `Interpreter._decref` (GH-139104)
(cherry picked from commit 571210b8f3)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
parent
5b64b59618
commit
070993b8ad
3 changed files with 24 additions and 2 deletions
|
|
@ -149,12 +149,17 @@ def __del__(self):
|
||||||
def __reduce__(self):
|
def __reduce__(self):
|
||||||
return (type(self), (self._id,))
|
return (type(self), (self._id,))
|
||||||
|
|
||||||
def _decref(self):
|
# gh-135729: Globals might be destroyed by the time this is called, so we
|
||||||
|
# need to keep references ourself
|
||||||
|
def _decref(self, *,
|
||||||
|
InterpreterNotFoundError=InterpreterNotFoundError,
|
||||||
|
_interp_decref=_interpreters.decref,
|
||||||
|
):
|
||||||
if not self._ownsref:
|
if not self._ownsref:
|
||||||
return
|
return
|
||||||
self._ownsref = False
|
self._ownsref = False
|
||||||
try:
|
try:
|
||||||
_interpreters.decref(self._id)
|
_interp_decref(self._id)
|
||||||
except InterpreterNotFoundError:
|
except InterpreterNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -419,6 +419,21 @@ def test_pickle(self):
|
||||||
unpickled = pickle.loads(data)
|
unpickled = pickle.loads(data)
|
||||||
self.assertEqual(unpickled, interp)
|
self.assertEqual(unpickled, interp)
|
||||||
|
|
||||||
|
@support.requires_subprocess()
|
||||||
|
@force_not_colorized
|
||||||
|
def test_cleanup_in_repl(self):
|
||||||
|
# GH-135729: Using a subinterpreter in the REPL would lead to an unraisable
|
||||||
|
# exception during finalization
|
||||||
|
repl = script_helper.spawn_python("-i")
|
||||||
|
script = b"""if True:
|
||||||
|
from concurrent import interpreters
|
||||||
|
interpreters.create()
|
||||||
|
exit()"""
|
||||||
|
stdout, stderr = repl.communicate(script)
|
||||||
|
self.assertIsNone(stderr)
|
||||||
|
self.assertNotIn(b"Traceback", stdout)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestInterpreterIsRunning(TestBase):
|
class TestInterpreterIsRunning(TestBase):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix unraisable exception during finalization when using
|
||||||
|
:mod:`concurrent.interpreters` in the REPL.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue