Skip to content

Commit

Permalink
Merge pull request #7782 from evanmiller/webp-get-next-without-gil
Browse files Browse the repository at this point in the history
Release GIL while calling `WebPAnimDecoderGetNext`
  • Loading branch information
radarhere committed Feb 22, 2024
2 parents 9441855 + b5c6f20 commit f8a54b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/releasenotes/10.3.0.rst
Expand Up @@ -79,3 +79,9 @@ Portable FloatMap (PFM) images

Support has been added for reading and writing grayscale (Pf format)
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.
7 changes: 6 additions & 1 deletion src/_webp.c
Expand Up @@ -448,11 +448,16 @@ PyObject *
_anim_decoder_get_next(PyObject *self) {
uint8_t *buf;
int timestamp;
int ok;
PyObject *bytes;
PyObject *ret;
ImagingSectionCookie cookie;
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");
return NULL;
}
Expand Down

0 comments on commit f8a54b7

Please sign in to comment.