Thread states and the global interpreter lock — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Interpreter initialization and finalization

Synchronization primitives

Python Module Index

3.16.0a0 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()

Manage the thread state explicitly with PyThreadState_New(), attaching and detaching it with PyEval_RestoreThread() and PyEval_SaveThread(). This happens in three distinct phases, at different points in the thread’s life

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.