FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-155997: Fix list_all() if an interpreter is destroyed during the call (GH-155998) by miss-islington · Pull Request #156005 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 8 additions & 2 deletions Lib/concurrent/interpreters/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ def create():

def list_all():
"""Return all existing interpreters."""
return [Interpreter(id, _whence=whence)
for id, whence in _interpreters.list_all(require_ready=True)]
interps = []
for id, whence in _interpreters.list_all(require_ready=True):
try:
interps.append(Interpreter(id, _whence=whence))
except InterpreterNotFoundError:
# It was destroyed after it was listed.
pass
return interps


def get_current():
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_interpreters/test_api.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,21 @@ def test_idempotent(self):
for interp1, interp2 in zip(actual, expected):
self.assertIs(interp1, interp2)

def test_destroyed_by_gc(self):
# gh-155997: the interpreter is destroyed while list_all() runs.
interp = interpreters.create()
interpid = interp.id
cycle = []
cycle.append(cycle)
cycle.append(interp)
# The cycle holds the only reference, so only the collector frees it.
with support.disable_gc():
del interp, cycle

with support.gc_threshold(1):
ids = [i.id for i in interpreters.list_all()]
self.assertNotIn(interpid, ids)

def test_created_with_capi(self):
mainid, *_ = _interpreters.get_main()
interpid1 = _interpreters.create()
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :func:`concurrent.interpreters.list_all`. It failed if an interpreter
was destroyed during the call, in particular by a garbage collection which
finalized the object owning the last reference to it.
Loading

Back | FazBrowse Home | New Git URL