Skip to content

Commit 9ac4b4a

Browse files
Clarify the relationship betwwen OS threads and Python threads and interpreters.
1 parent 17a2f34 commit 9ac4b4a

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Doc/reference/executionmodel.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,20 +446,24 @@ exception and the Python call stack.
446446
In between the global runtime and the thread(s) lies the interpreter.
447447
It completely encapsulates all of the non-process-global runtime state
448448
that the interpreter's Python threads share. For example, all its
449-
threads share :data:`sys.modules`. When a Python thread is created,
450-
it belongs to an interpreter, and likewise when an OS thread is
451-
otherwise associated with Python.
449+
threads share :data:`sys.modules`. Every Python thread belongs to a
450+
single interpreter and runs using that shared state. The initial
451+
interpreter is known as the "main" interpreter, and the initial thread,
452+
where the runtime was initialized, is known as the "main" thread.
452453

453454
.. note::
454455

455456
The interpreter here is not the same as the "bytecode interpreter",
456457
which is what runs in each thread, executing compiled Python code.
457458

458-
If the runtime supports using multiple interpreters then each OS thread
459-
will have at most one Python thread for each interpreter. However,
460-
only one is active in the OS thread at a time. Switching between
461-
interpreters means changing the active Python thread.
462-
The initial interpreter is known as the "main" interpreter.
459+
Every Python thread is associated with a single OS thread, which is
460+
where it runs. However, multiple Python threads can be associated with
461+
the same OS thread. For example, an OS thread might run code with a
462+
first interpreter and then with a second, each necessarily with its own
463+
Python thread. Still, regardless of how many are *associated* with
464+
an OS thread, only one Python thread can be actively *running* in
465+
an OS thread at a time. Switching between interpreters means
466+
changing the active Python thread.
463467

464468
Once a program is running, new Python threads can be created using the
465469
:mod:`threading` module (on platforms and Python implementations that

0 commit comments

Comments
 (0)