gh-80406: Finalise subinterpreters in Py_FinalizeEx()#17575
Conversation
|
I need to look into |
Sorry, something went wrong.
|
As noted here, it seems |
Sorry, something went wrong.
ericsnowcurrently
left a comment
There was a problem hiding this comment.
Thanks for working on this! The approach makes sense, including the flag (and where you put it). My comments are basically:
- questions about a few details
- point out missing test code
- a recommendation about the name (and meaning) of the new flag
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
|
@LewisGaul, please take a look at the code reviews and requested changes. Thank you! |
Sorry, something went wrong.
|
@csabella Yes I haven't forgotten this, I've been a bit busy. I have plans to work on this, hopefully soon. |
Sorry, something went wrong.
|
@LewisGaul, thank you for the update. I just wanted to make sure you were aware that it had been reviewed. 🙂 |
Sorry, something went wrong.
…test to test_embed.py
…to finalise-subinterps
|
On Sat., 25 Jan. 2020, 7:45 am Eric Snow, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Include/internal/pycore_pystate.h
<#17575 (comment)>:
> @@ -226,6 +226,7 @@ typedef struct pyruntimestate {
If that becomes a problem later then we can adjust, e.g. by
using a Python int. */
int64_t next_id;
+ int finalizing;
I guess it's a bit vague. "new" what? Honestly, the flag represents more
than just the availability of subinterpreters. So I'd probably feel more
comfortable with "ready" (or "available"), which would mean "the full
capability of the C-API is available" (including subinterpreters).
@ncoghlan <https://github.com/ncoghlan>, what do you think?
My expectation with the naming suggestion is that we use the flag to mean
"`Py_NewInterpreter` will now work". It's true it could be seen as
ambiguous with the more general meaning "allow new objects" (based on the
name of the tp_new slot and associated Python magic method), so I'd also be
OK with expanding it to be the more explicit "allow_new_interpreters".
I don't think we'd be helping anyone by making the flag itself ambiguous,
though, so I think we should stick with the concrete meaning of
"`Py_NewInterpreter` will always fail immediately when this is not set".
|
Sorry, something went wrong.
Fair enough. I guess I'm thinking about future stuff, but we can address that later (when needed). 😄 |
Sorry, something went wrong.
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
|
I've resolved conflicts with upstream. Current status:
|
Sorry, something went wrong.
ericsnowcurrently
left a comment
There was a problem hiding this comment.
Thanks for sticking with this! You're on the right track. I've noted 2 things that should be adjusted. I'll address the test cases separately.
We also discussed some refactoring that would help establish as safer order of operations during runtime finalization (and likewise initialization). However, those can be handled separately.
Sorry, something went wrong.
I don't see Victor's concerns as a problem for this PR. The impact is low and the result is an error before anything happens rather than doing anything improper or unexpected. I'll leave a note in the issue to that effect.
I still think each of those cases should be covered by tests, except maybe the one about daemon threads. I'm not sure how you would write a test that wouldn't fail sporadically with the current behavior. Maybe block a daemon thread and unblock it in an atexit handler (which would be triggered after non-daemon threads would have already finished. Then you can verify that the daemon thread did not block |
Sorry, something went wrong.
|
As I wrote in https://bugs.python.org/issue36225 I'm not excited by the idea of finalizing subinterpreters by executing their object finalizers in the main interpreter. |
Sorry, something went wrong.
Thanks for the input @vstinner. @ericsnowcurrently it would be good to get your thoughts here. I'm happy to change the implementation to satisfy whichever solution we settle on. |
Sorry, something went wrong.
|
The following commit authors need to sign the Contributor License Agreement: |
Sorry, something went wrong.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
|
Thanks for the interesting in contributing, however I'm closing as this is stale, awaiting changes, and CLA unsigned. |
Sorry, something went wrong.
Programs/_testembed.c- previously failing, now passingPy_FinalizeEx()and callPy_EndInterpreter()_PyRuntime.interpreters.allow_newto prevent new subinterpreters from being created during finalisationPy_FinalizeEx()from a subinterpreter (to be changed at a later stage)https://bugs.python.org/issue36225
Also addresses bpo-38865 and bpo-37776.