{{ message }}
gh-111916: Make hashlib related modules thread-safe without the GIL - #111981
Merged
Conversation
colesbury
reviewed
Nov 13, 2023
Contributor
There was a problem hiding this comment.
The build errors you're seeing are due to md5module.c being compiled with the limited API, which means internal-only functions like PyMutex_Lock are not available. You should remove these lines from md5module.c:
#ifndef _MSC_VER
#include "pyconfig.h" // Py_NOGIL
#endif
#ifndef Py_NOGIL
// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
#define Py_LIMITED_API 0x030c0000
#endif
And instead add:
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
Contributor
Contributor
|
It looks like some of the generated parts of |
Member
Author
|
Thanks for the thorough review! I reran AC as you suggested, so hopefully it should be good this time |
gpshead
reviewed
Nov 15, 2023
gpshead
approved these changes
Nov 15, 2023
gpshead
left a comment
Member
There was a problem hiding this comment.
one minor style nit, overall looks great. thanks!
Member
gpshead
enabled auto-merge (squash)
November 15, 2023 23:37
aisk
pushed a commit
to aisk/cpython
that referenced
this pull request
Feb 11, 2024
… GIL (python#111981) Always use an individual lock on hash objects when in free-threaded builds. Fixes python#111916
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this pull request
Sep 2, 2024
… GIL (python#111981) Always use an individual lock on hash objects when in free-threaded builds. Fixes python#111916
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.

Still a work in progress but I'd be happy for feedback ;)
I'm not entirely sure what to do about
HASHLIB_GIL_MINSIZE. IIUC the original code avoids releasing the GIL and getting a separate lock when the update buffer is short enough. I'm guessing that in the nogil version, we'll have to lock the mutex regardless of the length (i.e. essentially getting rid of the macro)? Is that correct?As a side note, I'm failing to build this PR with the GIL enabled. Running
./configure --with-pydebugandmake -s -j2, I'm getting this error:Even if I add
#include "pyatomic.h"topycore_lock.hI get the same error.. any idea why that is?Fixes #111916