Skip to content

feat: Embeded sub-interpreters #5666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6f5b38d
First draft a subinterpreter embedding API
b-pass May 15, 2025
ee42fe5
Move subinterpreter tests to their own file
b-pass May 18, 2025
45159fd
Migrate subinterpreter tests to use the new embedded class.
b-pass May 16, 2025
5b5a1e8
Add a test for moving subinterpreters across threads for destruction
b-pass May 18, 2025
74080eb
Code organization
b-pass May 16, 2025
51764f0
Add a test which shows demostrates how gil_scoped interacts with sub-…
b-pass May 16, 2025
68543fa
Add documentation for embeded sub-interpreters
b-pass May 18, 2025
7a00f32
Some additional docs work
b-pass May 16, 2025
e903406
Add some convenience accessors
b-pass May 16, 2025
70c24e8
Add some docs cross references
b-pass May 18, 2025
3c78e4b
Sync some things that were split out into #5665
b-pass May 18, 2025
ca44bfe
Update subinterpreter docs example to not use the CPython api
b-pass May 17, 2025
e9b2a57
Fix pip test
b-pass May 17, 2025
096afd9
style: pre-commit fixes
pre-commit-ci[bot] May 17, 2025
9db4f32
Fix MSVC warnings
b-pass May 17, 2025
a536fdc
Add some sub-headings to the docs
b-pass May 17, 2025
29e3171
Oops, make_unique is C++14 so remove it from the tests.
b-pass May 17, 2025
d4b1c44
I think this fixes the EndInterpreter issues on all versions.
b-pass May 18, 2025
eda11c1
Add a note about exceptions.
b-pass May 18, 2025
cd12019
style: pre-commit fixes
pre-commit-ci[bot] May 18, 2025
bddcfb5
Add try/catch to docs examples to match the tips
b-pass May 18, 2025
8770bfa
Python 3.12 is very picky about this first PyThreadState
b-pass May 19, 2025
ae097c8
style: pre-commit fixes
pre-commit-ci[bot] May 19, 2025
6062230
Missed a rename in a ifdef block
b-pass May 19, 2025
2aae3b8
I think this test is causing problems in 3.12, so try ifdefing it to …
b-pass May 19, 2025
dc57729
style: pre-commit fixes
pre-commit-ci[bot] May 19, 2025
ae0da30
Document the 3.12 constraints with a warning
b-pass May 19, 2025
68c68d7
Apply suggestions from code review
henryiii May 20, 2025
30c520b
ci: add cpptest to the clang-tidy job
henryiii May 20, 2025
babf12a
noexcept move operations
b-pass May 20, 2025
59f82a2
Update include/pybind11/subinterpreter.h
b-pass May 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Copilot <[email protected]>
  • Loading branch information
henryiii and Copilot authored May 20, 2025
commit 68c68d7d160612369a0c4b35644a1d83f2817ce5
2 changes: 1 addition & 1 deletion docs/advanced/embedding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Activating a Sub-interpreter
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Once a sub-interpreter is created, you can "activate" it on a thread (and
acquire it's GIL) by creating a :class:`subinterpreter_scoped_activate`
acquire its GIL) by creating a :class:`subinterpreter_scoped_activate`
instance and passing it the sub-intepreter to be activated. The function
will acquire the sub-interpreter's GIL and make the sub-interpreter the
current active interpreter on the current thread for the lifetime of the
Expand Down
8 changes: 4 additions & 4 deletions include/pybind11/subinterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ PYBIND11_NAMESPACE_END(detail)

class subinterpreter;

/// Activate the subinterpreter and acquire it's GIL, while also releasing any GIL and interpreter
/// currently held. Upon exiting the scope, the previous subinterpreter (if any) and it's
/// Activate the subinterpreter and acquire its GIL, while also releasing any GIL and interpreter
/// currently held. Upon exiting the scope, the previous subinterpreter (if any) and its
/// associated GIL are restored to their state as they were before the scope was entered.
class subinterpreter_scoped_activate {
public:
Expand Down Expand Up @@ -263,8 +263,8 @@ inline subinterpreter_scoped_activate::subinterpreter_scoped_activate(subinterpr
return;
}

// we can't really innteract with the interpreter at all until we switch to it
// not even to, for example, look in it's state dict or touch its internals
// we can't really interact with the interpreter at all until we switch to it
// not even to, for example, look in its state dict or touch its internals
tstate_ = PyThreadState_New(si.istate_);

// make the interpreter active and acquire the GIL
Expand Down
Loading