Skip to content

Commit 60fa8b3

Browse files
bpo-44145: Release the GIL around HMAC_Update. (GH-26157)
It was always meant to be released for parallelization. This now matches the other similar code in the module. Thanks michaelforney for noticing! (cherry picked from commit c10392e) Co-authored-by: Gregory P. Smith <[email protected]>
1 parent e6755ba commit 60fa8b3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`hmac` computations were not releasing the GIL while calling the
2+
OpenSSL ``HMAC_Update`` C API (a new feature in 3.9). This unintentionally
3+
prevented parallel computation as other :mod:`hashlib` algorithms support.

Modules/_hashopenssl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,11 @@ _hmac_update(HMACobject *self, PyObject *obj)
14961496
}
14971497

14981498
if (self->lock != NULL) {
1499-
ENTER_HASHLIB(self);
1499+
Py_BEGIN_ALLOW_THREADS
1500+
PyThread_acquire_lock(self->lock, 1);
15001501
r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len);
1501-
LEAVE_HASHLIB(self);
1502+
PyThread_release_lock(self->lock);
1503+
Py_END_ALLOW_THREADS
15021504
} else {
15031505
r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len);
15041506
}

0 commit comments

Comments
 (0)