Thread states and the global interpreter lock — Python 3.14.7 documentation

docs.python.org

Tin mới

Interpreter initialization and finalization

Synchronization primitives

Python Module Index

3.14.7 Documentation

Python/C API reference manual

free-threaded build

As such, only a thread that holds the GIL may operate on Python objects or invoke Python’s C API.

sys.setswitchinterval()

As such, only a thread that holds the GIL may operate on Python objects or invoke Python’s C API.

zlib: Low-level interface to compression and decompression routines compatible with gzip.

Performing blocking I/O is the most common use case for detaching the thread state, but it is also useful to call it over long-running native code that doesn’t need access to Python objects or Python’s C API. For example

hashlib: Secure hash and message digest algorithms.

Performing blocking I/O is the most common use case for detaching the thread state, but it is also useful to call it over long-running native code that doesn’t need access to Python objects or Python’s C API. For example

threading: Thread-based parallelism.

When threads are created using the dedicated Python APIs (such as the threading module), a thread state is automatically associated with them, However, when a thread is created from native code (for example, by a third-p

PyInterpreterState_Get()

PyThreadState_New requires an argument pointing to the desired interpreter; such a pointer can be acquired via a call to PyInterpreterState_Get() from the code where the thread was created.

Cautions about fork()¶

Another important thing to note about threads is their behaviour in the face of the C fork() call. On most systems with fork(), after a process forks only the thread that issued the fork will exist. This has a concrete i

PyOS_AfterFork_Child()

Another important thing to note about threads is their behaviour in the face of the C fork() call. On most systems with fork(), after a process forks only the thread that issued the fork will exist. This has a concrete i

PyEval_SetProfile()

Resume tracing and profiling in the Python thread state tstate suspended by the PyThreadState_EnterTracing() function.

Py_EnterRecursiveCall()

Set the stack protection start address and stack protection size of a Python thread state.