Use PyEval_InitThreads() as intended#4350
Conversation
https://docs.python.org/3.6/c-api/init.html#c.PyEval_InitThreads > This function is not available when thread support is disabled at compile time.
|
@eacousineau there is no specific reason for requesting a review from you, but @henryiii has been unresponsive for 3 weeks. It would be great if you could help out with a second set of eyes. |
EricCousineau-TRI
left a comment
There was a problem hiding this comment.
Sounds good, and thanks for the writeup! Though I'm afraid I may be a bit slow to catch up on the issues.
It's hard for me to posit from above Windows-based failure that the above indicated misplacement. Can I ask if the following is the correct reasoning, reasoning within Python 3.6?
- Calling
PyEval_InitThreads()inget_internals()via nominal usage did nothing per 3.6 docs stating that "This is a no-op when called for a second time", so this is a harmless (but noisy) misplacement. - The missing call in
embed.hare why Windows (and others?) fail. This smells like it'd happen when the embedded interpreter exits beforeget_internals()was called. Is this the case? (is it spurious, or deterministic?)
…t is always false.
EricCousineau-TRI
left a comment
There was a problem hiding this comment.
Still not sure on the whole of the changes (per questions in first post), but def. won't block progress - thanks!
Sorry I wasn't able to finish the below before a long meeting, continuing now ...
Yes, in the sense that it is harmless if there is actually a correct placement. That's not the case before this PR. I was thinking of "misplaced" as in "we're moving it from the wrong place to the right place".
Not deterministic. "flaky" is the term I see getting used around Google. My understanding is not complete, but IIUC the Python documentation correctly, prior to Python 3.7,
is before this:
Now pure speculation: I think that the "non-simple" code in gil.h covered that up, somehow. I'm thinking that because we didn't see the flakiness I'm trying to fix with this PR before PR #4216. Thanks for the approvals! |
|
Sweet, that all makes sense - thanks for the thorough response! |
Description
This PR actually matters
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON(evidently, based on CI flakes observed since PR AddPYBIND11_SIMPLE_GIL_MANAGEMENToption (cmake, C++ define) #4216 was merged),Hypothesis:
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFFcovers up thatPyEval_InitThreads()was misplaced.This PR almost does not matter anymore at all:
Note that Python 3.6 EOL was 2021-12-23 (https://endoflife.date/python), but since PR #4216 was merged we had distracting CI flakes that this PR aims to get rid of, e.g.:
Suggested changelog entry:
Bug fix affecting only Python 3.6 under very specific, uncommon conditions: move ``PyEval_InitThreads()`` call to the correct location.