gh-140746: Fix Thread.start() that can hang indefinitely - v2#144750
gh-140746: Fix Thread.start() that can hang indefinitely - v2#144750YvesDup wants to merge 6 commits intopython:mainfrom
Conversation
bkap123
left a comment
There was a problem hiding this comment.
Left a couple of small comments on semantics.
| @@ -0,0 +1,2 @@ | |||
| Fix :func:`threading.Thread.start` that can hang indefinitely in case of heap memory exhaustion | |||
| during initialization of the new thread. | |||
There was a problem hiding this comment.
Maybe add something about the new FAILED state that is managed by the C code?
ryv-odoo
left a comment
There was a problem hiding this comment.
Hello @YvesDup ,
Now I understand what you meant in your comment 😄. Sorry I certainly misunderstood your comment at the time.
This version changes the behavior slightly from mine: The serving thread (aka the one who call start() on the new Thread) will crash (raise an exception) because of an error raised from the new Thread.
I am not a huge fan of this change because it means that the serving thread might not recover from it (and I feel that errors from sub thread shouldn't impact the parent Thread). But I don't have a strong opinion about it 🤔
I will apply the comments of @bkap123 in my branch since they mainly target my code.
Have a nice day.
Hi @ryv-odoo , In this PR, it is possible to wait in C and just cleans up the two dicts in the I proposed raising an exception because I would notify the devs that the new thread starts fine but fails before calling the |
rename bootstrapped => running remove "is_failed" method of ThreadHandle
|
|
||
| # Give the thread a moment to clean up after itself | ||
| # specially in free-threading builds. | ||
| time.sleep(0.1) |
There was a problem hiding this comment.
What's going on here? This looks like it's hiding some underlying problem.
This PR is based on the @ryv-odoo PR. I would have preferred to start from @ryv-odoo's PR branch rather than duplicating his code, but I don't know if that's possible.
Following the @colesbury comment,
I submit this PR that includes the waiting in C the module and raise a runtime exception when the thread handle state is set to failed. This exception is treated in the
Thread.start.