GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-39877: take_gil() now exits the thread if finalizing by vstinner · Pull Request #18854 · python/cpython Conversation
|
|
@pitrou: My previous change introduced a race condition: https://bugs.python.org/issue39877#msg363667 This change should fix it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I tested manually: with this change and PR #18848, asyncio_gc.py of bpo-19466 does no longer crash. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I believe the fix is somehow incomplete, see below.
Also, as you say, the problem is "is it safe to destroy the GIL if there are still daemon threads trying to take it?".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| MUTEX_UNLOCK(gil->mutex); | ||
|
|
||
| if (thread_must_exit(tstate)) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why you're doing this here. It doesn't seem necessary and, furthermore, it's unlikely to trigger.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This code path is to prevent https://bugs.python.org/issue39877#msg363667 crash. Are you suggesting to move this code at line 249, after COND_TIMED_WAIT()?
thread_must_exit() at entry is to prevent https://bugs.python.org/issue39877#msg363512 crash.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| int err = errno; | ||
|
|
||
| if (thread_must_exit(tstate)) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ok, but shouldn't you do this after COND_TIMED_WAIT below as well?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| to run after wait_for_thread_shutdown() and before Py_Finalize() | ||
| completes. For example, when _PyImport_Cleanup() executes Python | ||
| code. */ | ||
| MUTEX_UNLOCK(gil->mutex); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if anyone else should be done here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For example, is COND_SIGNAL(gil->cond) needed to wake up the next thread waiting on COND_TIMED_WAIT()?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have made the requested changes; please review again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for making the requested changes! @pitrou: please review the changes made to this pull request. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I merged PR #18890 which checks if the thread must exit at function exit as well. In short, it restores the Python 3.8 behavior. I close this PR for now. We can revisit take_gil() later to try to adjust/optimize it later. I prefer to move step by step. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.