@@ -416,14 +416,19 @@ on the computer look something like this::
416416
417417 While a program always starts with exactly one of each of those, it may
418418grow to include multiple of each. Hosts and processes are isolated and
419- independent from one another. However, threads are not. Each thread
420- does *run * independently, for the small segments of time it is
421- scheduled to execute its code on the CPU. Otherwise, all threads
419+ independent from one another. However, threads are not.
420+
421+ Not all platforms support threads, though most do. For those that do,
422+ each thread does *run * independently, for the small segments of time it
423+ is scheduled to execute its code on the CPU. Otherwise, all threads
422424in a process share all the process' resources, including memory.
423- This is exactly what can make threads a pain: two threads running
424- at the same arbitrary time on different CPU cores can accidentally
425- interfere with each other's use of some shared data. The initial
426- thread is known as the "main" thread.
425+ The initial thread is known as the "main" thread.
426+
427+ .. note ::
428+
429+ The way they share resources is exactly what can make threads a pain:
430+ two threads running at the same arbitrary time on different CPU cores
431+ can accidentally interfere with each other's use of some shared data.
427432
428433The same layers apply to each Python program, with some extra layers
429434specific to Python::
@@ -435,20 +440,21 @@ specific to Python::
435440 Python thread (runs bytecode)
436441
437442When a Python program starts, it looks exactly like that, with one
438- of each. The process has a single global runtime to manage global
439- resources. Each Python thread has all the state it needs to run
443+ of each. The process has a single global runtime to manage Python's
444+ global resources. Each Python thread has all the state it needs to run
440445Python code (and use any supported C-API) in its OS thread.
441446
442447.. , including its stack of call frames.
443448
444449.. If the program uses coroutines (async) then the thread will end up
445450 juggling multiple stacks.
446451
447- In between the global runtime and the threads lies the interpreter.
448- It encapsulates all of the non-global runtime state that the
449- interpreter's Python threads share. For example, all those threads
450- share :data: `sys.modules `. When a Python thread is created, it belongs
451- to an interpreter.
452+ In between the global runtime and the thread(s) lies the interpreter.
453+ It completely encapsulates all of the non-global runtime state that the
454+ interpreter's Python threads share. For example, all its threads share
455+ :data: `sys.modules `. When a Python thread is created, it belongs
456+ to an interpreter, and likewise when an OS thread is otherwise
457+ associated with Python.
452458
453459If the runtime supports using multiple interpreters then each OS thread
454460will have at most one Python thread for each interpreter. However,
@@ -460,9 +466,10 @@ The initial interpreter is known as the "main" interpreter.
460466 of which each thread has one to execute Python code.)
461467
462468 Once a program is running, new Python threads can be created using the
463- :mod: `threading ` module. Additional processes can be created using the
464- :mod: `multiprocessing ` and :mod: `subprocess ` modules. You can run
465- coroutines (async) in the main thread using :mod: `asyncio `.
469+ :mod: `threading ` module (on platforms and Python implementations that
470+ support threads). Additional processes can be created using the
471+ :mod: `os `, :mod: `subprocess `, and :mod: `multiprocessing ` modules.
472+ You can run coroutines (async) in the main thread using :mod: `asyncio `.
466473Interpreters can be created using the :mod: `concurrent.interpreters `
467474module.
468475
0 commit comments