Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.13] gh-76785: Expand How Interpreter Queues Handle Interpreter Finalization (gh-116431)#121807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

miss-islington
Copy link
Contributor

@miss-islingtonmiss-islington commentedJul 15, 2024
edited by bedevere-appbot
Loading

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 commit6b98b27)

Co-authored-by: Eric Snowericsnowcurrently@gmail.com

…lization (pythongh-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 (pythongh-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 item2. raise an exception (interpreters.queues.ItemInterpreterDestroyed) from Queue.get() in place of each removed item3. 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 commit6b98b27)Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@miss-islington@ericsnowcurrently

[8]ページ先頭

©2009-2025 Movatter.jp