cpython/Lib/test/support
Miss Islington (bot) f19ccfdae0
[3.13] gh-76785: Expand How Interpreter Queues Handle Interpreter Finalization (gh-121807)
Any cross-interpreter mechanism for passing objects between interpreters must be very careful to respect isolation, even when the object is effectively immutable (e.g. int, str).  Here this especially relates to when an interpreter sends one of its objects, and then is destroyed while the inter-interpreter machinery (e.g. queue) still holds a reference to the object.

When I added interpreters.Queue, I dealt with that case (using an atexit hook) by silently removing all items from the queue that were added by the finalizing interpreter.

Later, while working on concurrent.futures.InterpreterPoolExecutor (gh-116430), I noticed it was somewhat surprising when items were silently removed from the queue when the originating interpreter was destroyed.  (See my comment on that PR.)
 It took me a little while to realize what was going on.  I expect that users, which much less context than I have, would experience the same pain.

My approach, here, to improving the situation is to give users three options:

1. return a singleton (interpreters.queues.UNBOUND) from Queue.get() in place of each removed item
2. raise an exception (interpreters.queues.ItemInterpreterDestroyed) from Queue.get() in place of each removed item
3. existing behavior: silently remove each item (i.e. Queue.get() skips each one)

The default will now be (1), but users can still explicitly opt in any of them, including to the silent removal behavior.

The behavior for each item may be set with the corresponding Queue.put() call. and a queue-wide default may be set when the queue is created.  (This is the same as I did for "synconly".)

(cherry picked from commit 6b98b274b6, AKA gh-116431)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-07-15 19:13:51 +00:00
..
_hypothesis_stubs GH-86275: Implementation of hypothesis stubs for property-based tests, with zoneinfo tests (#22863) 2023-05-12 08:35:53 -04:00
interpreters [3.13] gh-76785: Expand How Interpreter Queues Handle Interpreter Finalization (gh-121807) 2024-07-15 19:13:51 +00:00
__init__.py [3.13] gh-121571: Do not use `EnvironmentError` in tests, use `OSError` instead (GH-121572) (#121574) 2024-07-10 10:38:48 +00:00
ast_helper.py
asynchat.py
asyncore.py
bytecode_helper.py gh-117680: make _PyInstructionSequence a PyObject and use it in tests (#117629) 2024-04-17 16:42:04 +01:00
hashlib_helper.py
hypothesis_helper.py Disable `differing_test_runners` health check (#108886) 2023-09-04 18:31:58 +00:00
import_helper.py gh-76785: Rename _xxsubinterpreters to _interpreters (gh-117791) 2024-04-24 16:18:24 +00:00
logging_helper.py
os_helper.py gh-118201: Accomodate flaky behavior of `os.sysconf` on iOS (GH-118453) 2024-04-30 22:31:00 -04:00
pty_helper.py gh-108303: Move all doctest related files and tests to `Lib/test/test_doctest/` (#112109) 2024-01-18 16:58:11 +01:00
refleak_helper.py gh-80931: Skip some socket tests while hunting for refleaks on macOS (#114057) 2024-01-21 11:25:15 +01:00
script_helper.py gh-112536: Add test_threading to TSAN tests (#116898) 2024-03-16 11:55:46 +00:00
smtpd.py gh-108303: Move `smtpd` to `test.support` (#114368) 2024-01-22 14:36:29 +01:00
socket_helper.py gh-109015: Add test.support.socket_helper.tcp_blackhole() (#109016) 2023-09-07 01:58:03 +02:00
testcase.py
threading_helper.py gh-111644: Fix support threading_cleanup() (#111714) 2023-11-04 00:18:42 +00:00
warnings_helper.py