[Python Fork] Use os.register_at_fork instead of pthread_atfork.#32935
Merged
XuanWang-Amos merged 2 commits intogrpc:masterfrom Apr 25, 2023
Merged
[Python Fork] Use os.register_at_fork instead of pthread_atfork.#32935XuanWang-Amos merged 2 commits intogrpc:masterfrom
XuanWang-Amos merged 2 commits intogrpc:masterfrom
Conversation
drfloob
approved these changes
Apr 25, 2023
Member
drfloob
left a comment
There was a problem hiding this comment.
LGTM, pending Python tests passing. I can confirm that this fix removes the fork-hang problem I was able to reproduce in my work. I'm comfortable landing this, but @gnossen please also sanity check this before the next release at the end of May, just to be safe.
XuanWang-Amos
added a commit
to XuanWang-Amos/grpc
that referenced
this pull request
May 1, 2023
…c#32935) Fix: grpc#18075 From comments in grpc#18075, `CPython` reinitialize the `GIL` after `pthread_atfork` child handler, thus we shouldn't use any `GIL` related functions in child handler which is what we're currently doing, this PR uses `os.register_at_fork` to replace `pthread_atfork` to prevent any undesired bevahior. This also seems to fixes a thread hanging issue cased by changes in core: grpc#32869 ### Testing: * Passed existing fork tests. (Note that due to some issues in `Bazel`, this change was not verified by `Bazel runs_per_test`). * Tested by patch the core PR, was able to fix Python fork tests: grpc#32933
paulosjca
pushed a commit
to paulosjca/grpc
that referenced
this pull request
May 4, 2023
…c#32935) Fix: grpc#18075 From comments in grpc#18075, `CPython` reinitialize the `GIL` after `pthread_atfork` child handler, thus we shouldn't use any `GIL` related functions in child handler which is what we're currently doing, this PR uses `os.register_at_fork` to replace `pthread_atfork` to prevent any undesired bevahior. This also seems to fixes a thread hanging issue cased by changes in core: grpc#32869 ### Testing: * Passed existing fork tests. (Note that due to some issues in `Bazel`, this change was not verified by `Bazel runs_per_test`). * Tested by patch the core PR, was able to fix Python fork tests: grpc#32933
wanlin31
pushed a commit
that referenced
this pull request
May 18, 2023
) Fix: #18075 From comments in #18075, `CPython` reinitialize the `GIL` after `pthread_atfork` child handler, thus we shouldn't use any `GIL` related functions in child handler which is what we're currently doing, this PR uses `os.register_at_fork` to replace `pthread_atfork` to prevent any undesired bevahior. This also seems to fixes a thread hanging issue cased by changes in core: #32869 ### Testing: * Passed existing fork tests. (Note that due to some issues in `Bazel`, this change was not verified by `Bazel runs_per_test`). * Tested by patch the core PR, was able to fix Python fork tests: #32933
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: #18075
From comments in #18075,
CPythonreinitialize theGILafterpthread_atforkchild handler, thus we shouldn't use anyGILrelated functions in child handler which is what we're currently doing, this PR usesos.register_at_forkto replacepthread_atforkto prevent any undesired bevahior.This also seems to fixes a thread hanging issue cased by changes in core: #32869
Testing:
Bazel, this change was not verified byBazel runs_per_test).