Skip to content

Commit b58a95c

Browse files
Drop "call into Python" discussion.
1 parent bf1f1a2 commit b58a95c

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

Doc/reference/executionmodel.rst

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ multiple thread states.
506506
As a whole, the Python runtime consists of the global runtime state,
507507
interpreters, and thread states. The runtime ensures all that state
508508
stays consistent over its lifetime, particularly when used with
509-
multiple host threads. The runtime also exposes a way for host threads
510-
to "call into Python", which will be covered in the next subsection.
509+
multiple host threads.
511510

512511
The global runtime, at the conceptual level, is just a set of
513512
interpreters. While they are otherwise isolated and independent from
@@ -563,7 +562,9 @@ call stack. It may include other thread-specific resources.
563562
Each thread state, over its lifetime, is always tied to exactly one
564563
interpreter and exactly one host thread. It will only ever be used in
565564
that thread. In the other direction, a host thread may have many
566-
Python thread states tied to it, for different interpreters.
565+
Python thread states tied to it, for different interpreters or even the
566+
same interpreter. However, for any given host thread, only one of the
567+
thread states tied to it can be used by the thread at a time.
567568

568569
Once a program is running, new Python threads can be created using the
569570
:mod:`threading` module (on platforms and Python implementations that
@@ -573,41 +574,6 @@ You can run coroutines (async) in the main thread using :mod:`asyncio`.
573574
Interpreters can be created and used with the
574575
:mod:`~concurrent.interpreters` module.
575576

576-
Calls into Python
577-
-----------------
578-
579-
A "call into Python" is an abstraction of "ask the Python runtime
580-
to do something". It necessarily involves targeting a single runtime
581-
context, whether global, interpreter, or thread. The layer depends
582-
on the desired operation. Most operations require a thread state.
583-
584-
When a running host thread calls into Python, the actual mechanism
585-
is implementation-specific. For example, CPython provides a C-API and
586-
the thread will literally call into Python through a C-API function.
587-
588-
.. drop paragraph?
589-
590-
Some thread-specific operations must only target a new thread state,
591-
while others may target any thread state, including one with a Python
592-
call already on its stack or a current exception set.
593-
594-
A thread-specific call into Python can target only one thread state.
595-
That means, when there are multiple Python thread states tied to the
596-
current host thread, only one of them can be in use at a time. It
597-
doesn't matter if the thread states belong to different interpreters
598-
or the same interpreter.
599-
600-
Calls into Python can be nested. Even if a thread has already called
601-
into Python, that operation could be interrupted by another call into
602-
Python targeting a different runtime context. For example, the
603-
implementation of the outer call might make the inner call directly.
604-
Alternately, the host or Python runtime might trigger some
605-
asyncronous callback that calls into Python.
606-
607-
Regardless, at the point of the inner call, the target is swapped.
608-
When the inner call finishes, the target is swapped back and the outer
609-
call resumes.
610-
611577

612578
.. rubric:: Footnotes
613579

0 commit comments

Comments
 (0)