Skip to content

Release the GIL in decode_batch - #335

Open
akabel wants to merge 1 commit into
quantumlib:mainfrom
akabel:release-gil-in-decode-batch
Open

akabel wants to merge 1 commit into
quantumlib:mainfrom
akabel:release-gil-in-decode-batch

Conversation

@akabel

@akabel akabel commented Oct 14, 2026

Copy link
Copy Markdown

TesseractDecoder.decode_batch and SimplexDecoder.decode_batch held the GIL for the whole batch, so no other Python thread could run until they returned. That stalls threads that have to keep running while a batch decodes, e.g. a Pub/Sub client's lease manager in a worker that pulls batches from a queue: when it can't renew the lease in time, the batch is redelivered to another worker while it is still being decoded (this is my actual use case -- I am running tesseract's pybind interface in a cloud worker pool.)

The decoding loop touches no Python objects, so release the GIL while it runs. The new test checks that a countdown thread finishes while decode_batch decodes.

`TesseractDecoder.decode_batch` and `SimplexDecoder.decode_batch` held the
GIL for the whole batch, so no other Python thread could run until they
returned. That stalls threads that have to keep running while a batch
decodes, e.g. the Pub/Sub client's lease manager in a worker that pulls
batches from a queue: when it can't renew the lease in time, the batch is
redelivered to another worker while it is still being decoded.

The decoding loop touches no Python objects, so release the GIL while it
runs. The new test checks that a countdown thread finishes while
`decode_batch` decodes.
@akabel
akabel requested a review from a team as a code owner October 14, 2026 18:20
@akabel
akabel requested review from noajshu and removed request for a team October 14, 2026 18:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant