Skip to content

Release the GIL after importing the Python console - #538

Merged
lohedges merged 1 commit into
develfrom
fix_537
Nov 16, 2026
Merged

lohedges merged 1 commit into
develfrom
fix_537

Conversation

@lohedges

Copy link
Copy Markdown
Contributor

Closes #537.

The Python console's get_pyconsole() acquired the GIL to import sire.utils.Console but didn't release it on success, so the first console message from C++ with the GIL released (e.g. a warning during sire.convert.to_rdkit) left the thread holding the GIL. Restoring the thread state afterwards then hung on Python 3.12 and aborted on 3.13+.

This adds a ScopedGILAcquire helper next to ScopedGILRelease, uses it for all console calls, and replaces the private GILLock copies in the RDKit and QM wrappers. Failed console calls now clear the Python error, and the console destructor no longer deletes the Python object after decrementing its reference. A regression test converts a molecule with dummy atoms with MDAnalysis hidden, in a subprocess so that a hang fails the test.

Checklist

  • I confirm that I have merged the latest version of devel into this branch before issuing this pull request (e.g. by running git pull origin devel): [y]
  • I confirm that I have added a changelog entry to the changelog (we will add a link to this PR as part of the review): [y]
  • I confirm that I have permission to release this code under the MIT license (the Python API) or the LGPLv3+ license (everything else), as described in the LICENSE file: [y]

@lohedges lohedges added the bug Something isn't working label Nov 16, 2026
@lohedges
lohedges merged commit 3c32a7f into devel Nov 16, 2026
3 of 5 checks passed
@lohedges
lohedges deleted the fix_537 branch November 16, 2026 14:58

This branch was previously deployed

1 inactive deployment
sire-build — 86719fc4 Deployed Nov 16, 2026 by lohedges via build (3.13, linux) #475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Converting a molecule to RDKit hangs or aborts when a console warning is the first Python call with the GIL released

1 participant