Skip to content

Conversation

@glopesdev
Copy link
Member

@glopesdev glopesdev commented Mar 2, 2024

This PR adds initial support for explicitly controlling the state of the global interpreter lock. In preparation for Python 3.12 sub-interpreters, we decided to remove implicit locking throughout the scripting library. This meant instead introducing support for locking and releasing the GIL.

Since we expect most scripting operations to be called in tandem with workflow notifications, it is enough to lock the GIL during the call to OnNext, which can be implemented as a general wrapper (ObserveOnGIL) around any observable sequence.

Finally, to minimize the need for explicit locking, this PR also moves emission of the runtime upon creation inside the GIL, so initialization operators can be chained directly without explicitly grabbing the interpreter lock. A new operator GetRuntime is also introduced to retrieve the runtime manager and re-emit it inside the GIL for deferred operations. This pattern may be generalized in the future to sub-interpreters or modules as necessary.

Fixes #10

@glopesdev glopesdev added the feature New planned feature label Mar 2, 2024
@glopesdev glopesdev merged commit 41123c7 into bonsai-rx:main Mar 4, 2024
@glopesdev glopesdev deleted the gil-support branch March 4, 2024 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New planned feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for global interpreter lock

1 participant