Merge pull request #7782 from evanmiller/webp-get-next-without-gil

Release GIL while calling `WebPAnimDecoderGetNext`
This commit is contained in:
Andrew Murray 2024-02-22 21:50:41 +11:00 committed by GitHub
commit f8a54b78a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -79,3 +79,9 @@ Portable FloatMap (PFM) images
Support has been added for reading and writing grayscale (Pf format) Support has been added for reading and writing grayscale (Pf format)
Portable FloatMap (PFM) files containing ``F`` data. Portable FloatMap (PFM) files containing ``F`` data.
Release GIL when fetching WebP frames
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Python's Global Interpreter Lock is now released when fetching WebP frames from
the libwebp decoder.

View File

@ -448,11 +448,16 @@ PyObject *
_anim_decoder_get_next(PyObject *self) { _anim_decoder_get_next(PyObject *self) {
uint8_t *buf; uint8_t *buf;
int timestamp; int timestamp;
int ok;
PyObject *bytes; PyObject *bytes;
PyObject *ret; PyObject *ret;
ImagingSectionCookie cookie;
WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self; WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self;
if (!WebPAnimDecoderGetNext(decp->dec, &buf, &timestamp)) { ImagingSectionEnter(&cookie);
ok = WebPAnimDecoderGetNext(decp->dec, &buf, &timestamp);
ImagingSectionLeave(&cookie);
if (!ok) {
PyErr_SetString(PyExc_OSError, "failed to read next frame"); PyErr_SetString(PyExc_OSError, "failed to read next frame");
return NULL; return NULL;
} }