Commit Graph

7 Commits

Author SHA1 Message Date
Miss Islington (bot) 0e350d4bf6
[3.13] gh-125716: Use a Global Mutex When Initializing Global State For the _interpqueues Module (gh-125817)
This includes a drive-by cleanup in _queues_init() and _queues_fini().

This change also applies to the _interpchannels module.

(cherry picked from commit 4848b0b92c, AKA gh-125803)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-10-21 22:16:32 +00:00
Miss Islington (bot) b752764f9e
[3.13] gh-125716: Raise an Exception If _globals_init() Fails In the _interpqueues Module (gh-125808)
The fix applies to the _interpchannels module as well.

I've also included a drive-by typo fix for _interpqueues.

(cherry picked from commit 44f841f01a, AKA gh-125802)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-10-21 20:05:06 +00:00
Miss Islington (bot) e57831f301
[3.13] gh-125667: Statically Initialize the Arg Converter Data Values in _interpqueuesmodule.c (gh-125670)
gh-125667: Statically Initialize the Arg Converter Data Values in _interpqueuesmodule.c (gh-125668)
(cherry picked from commit 7cf2dbc3cb)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-10-18 00:13:54 +00:00
Miss Islington (bot) 835f4add60
[3.13] gh-76785: Expand How Interpreter Channels Handle Interpreter Finalization (gh-121811)
See 6b98b274b6 for an explanation of the problem and solution.  Here I've applied the solution to channels.

(cherry picked from commit 8b209fd4f8, AKA gh-121805)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-07-15 20:15:47 +00:00
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
Brett Simmers c2627d6eea
gh-116322: Add Py_mod_gil module slot (#116882)
This PR adds the ability to enable the GIL if it was disabled at
interpreter startup, and modifies the multi-phase module initialization
path to enable the GIL when loading a module, unless that module's spec
includes a slot indicating it can run safely without the GIL.

PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went
with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148.

A warning will be issued up to once per interpreter for the first
GIL-using module that is loaded. If `-v` is given, a shorter message
will be printed to stderr every time a GIL-using module is loaded
(including the first one that issues a warning).
2024-05-03 11:30:55 -04:00
Eric Snow 03e3e31723
gh-76785: Rename _xxsubinterpreters to _interpreters (gh-117791)
See https://discuss.python.org/t/pep-734-multiple-interpreters-in-the-stdlib/41147/26.
2024-04-24 16:18:24 +00:00