Python _thread: the low-level threading API under threading
Answer: The _thread module is a low-level threading API. The threading module wraps it at a higher level.
Threads
The module offers primitives for multiple threads of control that share a global data space, also called light-weight processes or tasks, and simple locks, also called mutexes or binary semaphores.
The module is always available from version 3.7.
error is raised on thread-specific errors and is a synonym of RuntimeError from version 3.3.
start_new_thread(function, args[, kwargs]) starts a new thread and returns its identifier. args must be a tuple. When the function returns, the thread exits silently. An unhandled exception is passed to sys.unraisablehook, and SystemExit from the function is ignored.
interrupt_main(signum=signal.SIGINT) simulates a signal arriving in the main thread, with no guarantee of an immediate interruption. If the signal is SIG_DFL or SIG_IGN, the function does nothing. The function schedules the associated handler. If you want to truly emit the signal, use signal.raise_signal.
exit() raises SystemExit. When not caught, the thread exits silently. get_ident() returns the current thread identifier, a nonzero integer. get_native_id() returns the native Thread ID assigned by the kernel, added in 3.8.
stack_size([size]) reports, or changes, the stack size used for new threads. 0 means the platform default, and a positive value must be at least 32,768 (32 KiB). Unsupported or invalid sizes raise RuntimeError or ValueError.
Locks
allocate_lock() returns a new unlocked lock. LockType is the type of lock objects.
acquire(blocking=True, timeout=-1) waits for the lock when blocking is true. When blocking is false, it takes the lock only if that can be done immediately. TIMEOUT_MAX is the maximum value allowed for the timeout parameter. A greater timeout raises OverflowError.
See also
Claims
- id: C1 claim: _thread offers low-level primitives for working with multiple threads. source: S1 evidence: "low-level primitives for working with multiple threads"
- id: C2 claim: threading is the easier, higher-level API built on this module. source: S2 evidence: "easier to use and higher-level"
- id: C3 claim: start_new_thread starts a thread and returns its identifier. source: S2 evidence: "Start a new thread and return its identifier"
Sources
- [S1] _thread — Low-level threading API. Python Software Foundation. https://docs.python.org/3/library/_thread.html . License: PSF License Version 2. Accessed 2026-11-27.
- [S2] _thread documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/_thread.rst . License: PSF License Version 2. Accessed 2026-11-27.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, _thread — Low-level threading API; CPython, _thread documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, _thread — Low-level threading API; CPython, _thread documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python _thread: the low-level threading API under threading." iinventedlight Library, iil:note:2qrfn9hw, version of 2026-11-27. https://iinventedlight.com/library/notes/python-thread/. License: CC-BY-4.0.
@misc{iil_note_2qrfn9hw,
author = {{iinventedlight}},
title = {{Python \_thread: the low-level threading API under threading}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-27},
url = {https://iinventedlight.com/library/notes/python-thread/},
note = {Permanent ID iil:note:2qrfn9hw. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-thread.schema.json (schema; CC-BY-4.0)
- python-thread.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-thread.md.