cpython/Lib/test/support
Eric Snow 6b98b274b6
gh-76785: Expand How Interpreter Queues Handle Interpreter Finalization (gh-116431)
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".)
2024-07-15 12:49:23 -06: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 gh-76785: Expand How Interpreter Queues Handle Interpreter Finalization (gh-116431) 2024-07-15 12:49:23 -06:00
__init__.py gh-121571: Do not use EnvironmentError in tests, use OSError instead (#121572) 2024-07-10 13:11:46 +03:00
ast_helper.py gh-100518: Add tests for ast.NodeTransformer (#100521) 2023-01-21 21:44:41 +00:00
asynchat.py gh-72719: Remove asyncore and asynchat modules (#96580) 2022-11-08 16:48:58 +01:00
asyncore.py gh-102799: use sys.exception() instead of sys.exc_info() in tests (#103293) 2023-04-06 11:08:25 +01:00
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 CI: set correct working directory for Hypothesis cache (GH-119345) 2024-05-29 14:13:18 +02: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 Move get_signal_name() to test.support (#121251) 2024-07-02 10:34:13 +02:00
smtpd.py Remove almost all unpaired backticks in docstrings (#119231) 2024-05-22 12:35:18 -04:00
socket_helper.py gh-109015: Add test.support.socket_helper.tcp_blackhole() (#109016) 2023-09-07 01:58:03 +02:00
testcase.py gh-103791: Make contextlib.suppress also act on exceptions within an ExceptionGroup (#103792) 2023-04-24 22:17:02 +00:00
threading_helper.py gh-111644: Fix support threading_cleanup() (#111714) 2023-11-04 00:18:42 +00:00
warnings_helper.py gh-103109: Document ignore_warnings() test support helper (#103110) 2023-04-03 00:18:25 +02:00