| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3833fa9 commit 9c1e2f0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,8 +68,14 @@ def create(): | |||
| 68 | 68 | ||
| 69 | 69 | def list_all(): | |
| 70 | 70 | """Return all existing interpreters.""" | |
| 71 | - return [Interpreter(id, _whence=whence) | ||
| 72 | - for id, whence in _interpreters.list_all(require_ready=True)] | ||
| 71 | + interps = [] | ||
| 72 | + for id, whence in _interpreters.list_all(require_ready=True): | ||
| 73 | + try: | ||
| 74 | + interps.append(Interpreter(id, _whence=whence)) | ||
| 75 | + except InterpreterNotFoundError: | ||
| 76 | + # It was destroyed after it was listed. | ||
| 77 | + pass | ||
| 78 | + return interps | ||
| 73 | 79 | ||
| 74 | 80 | ||
| 75 | 81 | def get_current(): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -289,6 +289,21 @@ def test_idempotent(self): | |||
| 289 | 289 | for interp1, interp2 in zip(actual, expected): | |
| 290 | 290 | self.assertIs(interp1, interp2) | |
| 291 | 291 | ||
| 292 | + def test_destroyed_by_gc(self): | ||
| 293 | + # gh-155997: the interpreter is destroyed while list_all() runs. | ||
| 294 | + interp = interpreters.create() | ||
| 295 | + interpid = interp.id | ||
| 296 | + cycle = [] | ||
| 297 | + cycle.append(cycle) | ||
| 298 | + cycle.append(interp) | ||
| 299 | + # The cycle holds the only reference, so only the collector frees it. | ||
| 300 | + with support.disable_gc(): | ||
| 301 | + del interp, cycle | ||
| 302 | + | ||
| 303 | + with support.gc_threshold(1): | ||
| 304 | + ids = [i.id for i in interpreters.list_all()] | ||
| 305 | + self.assertNotIn(interpid, ids) | ||
| 306 | + | ||
| 292 | 307 | def test_created_with_capi(self): | |
| 293 | 308 | mainid, *_ = _interpreters.get_main() | |
| 294 | 309 | interpid1 = _interpreters.create() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Fix :func:`concurrent.interpreters.list_all`. It failed if an interpreter | ||
| 2 | + was destroyed during the call, in particular by a garbage collection which | ||
| 3 | + finalized the object owning the last reference to it. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments