Skip to content

Commit ae0da30

Browse files
b-passhenryiii
authored andcommitted
Document the 3.12 constraints with a warning
1 parent dc57729 commit ae0da30

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

docs/advanced/embedding.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,14 @@ Expected output:
448448
After Main, still within sub; Current Interpreter is 1
449449
At end; Current Interpreter is 0
450450
451+
.. warning::
452+
453+
In Python 3.12 sub-interpreters must be destroyed in the same OS thread
454+
that created them. Failure to follow this rule may result in deadlocks
455+
or crashes when destroying the sub-interpreter on the wrong thread.
456+
457+
This constraint is not present in Python 3.13+.
458+
451459

452460
Best Practices for sub-interpreter safety
453461
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -458,7 +466,8 @@ Best Practices for sub-interpreter safety
458466
and :func:`error_already_set::what()` acquires the GIL. So Python exceptions must
459467
**never** be allowed to propagate past the enclosing
460468
:class:`subinterpreter_scoped_activate` instance!
461-
(So your try/catch should be *just inside* the scope covered by the :class:`subinterpreter_scoped_activate`.)
469+
(So your try/catch should be *just inside* the scope covered by the
470+
:class:`subinterpreter_scoped_activate`.)
462471

463472
- Avoid global/static state whenever possible. Instead, keep state within each interpreter,
464473
such as within the interpreter state dict, which can be accessed via
@@ -480,6 +489,7 @@ Best Practices for sub-interpreter safety
480489

481490
- When using multiple threads to run independent sub-interpreters, the independent GILs allow
482491
concurrent calls from different interpreters into the same C++ code from different threads.
483-
So you must still consider the thread safety of your C++ code.
492+
So you must still consider the thread safety of your C++ code. Remember, in Python 3.12
493+
sub-interpreters must be destroyed on the same thread that they were created on.
484494

485495
- Familiarize yourself with :ref:`misc_concurrency`.

0 commit comments

Comments
 (0)