_thread
| Use Case | Command | Description |
|---|---|---|
| 🌀 Create a new thread | _thread.start_new_thread(function, args) | Start a new thread and return its identifier |
| 🔒 Create a lock | _thread.allocate_lock() | Return a new lock object |
| 🆔 Get current thread identifier | _thread.get_ident() | Return non-zero integer identifying current thread |
| 🆔 Get native thread identifier | _thread.get_native_id() | Return OS-level thread identifier |
| 📏 Set thread stack size | _thread.stack_size([size]) | Set/return thread stack size in bytes |
| 🚦 Interrupt main thread | _thread.interrupt_main(signum) | Simulate signal arrival in main thread |
| 🚪 Exit current thread | _thread.exit() | Raise SystemExit to exit thread silently |
https://docs.python.org/3.10/library/_thread.html
The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.
This module provides primitive operations to write multi-threaded programs. The 'threading' module provides a more convenient interface.
A lock object is a synchronization primitive. To create a lock, call threading.Lock(). Methods are:
acquire() — lock the lock, possibly blocking until it can be obtainedrelease() — unlock of the locklocked() — test whether the lock is currently lockedA lock is not owned by the thread that locked it; another thread may unlock it. A thread attempting to lock a lock that it has already locked will block until another thread unlocks it. Deadlocks may ensue.
Methods defined here:
__enter__(...)acquire(blocking=True, timeout=-1) -> boolacquire_lock() is an obsolete synonym)__exit__(...)release()release_lock() is an obsolete synonym)__repr__(self, /)acquire(...)acquire(blocking=True, timeout=-1) -> boolacquire_lock() is an obsolete synonym)acquire_lock(...)acquire().locked(...)locked() -> boollocked_lock() is an obsolete synonym)locked_lock(...)locked().release(...)release()release_lock() is an obsolete synonym)release_lock(...)release().Methods defined here:
__enter__(...)acquire(blocking=True) -> boolblocking indicates whether we should wait for the lock to be available or not. If blocking is False and another thread holds the lock, the method will return False immediately. If blocking is True and another thread holds the lock, the method will wait for the lock to be released, take it and then return True. (note: the blocking operation is interruptible.) In all other cases, the method will return True immediately. Precisely, if the current thread already holds the lock, its internal counter is simply incremented. If nobody holds the lock, the lock is taken and its internal counter initialized to 1.__exit__(...)release()RuntimeError is raised. Do note that if the lock was acquire()d several times in a row by the current thread, release() needs to be called as many times for the lock to be available for other threads.__repr__(self, /)acquire(...)acquire(blocking=True) -> bool__enter__).release(...)release()__exit__).Static methods defined here:
__new__(*args, **kwargs) from builtins.typeallocate(...)allocate_lock() -> lock objectallocate() is an obsolete synonym)allocate_lock(...)allocate().exit(...)exit()exit_thread() is an obsolete synonym)raise SystemExit. It will cause the current thread to exit silently unless the exception is caught.exit_thread(...)exit().get_ident(...)get_ident() -> integerget_native_id(...)get_native_id() -> integerinterrupt_main(...)interrupt_main(signum=signal.SIGINT, /)signum is omitted, SIGINT is assumed. A subthread can use this function to interrupt the main thread. Note: the default signal handler for SIGINT raises KeyboardInterrupt.stack_size(...)stack_size([size]) -> sizestart_new(...)start_new_thread(function, args[, kwargs])start_new() is an obsolete synonym)start_new_thread(...)start_new().TIMEOUT_MAX = 9223372036.0
(built-in)
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-01 16:50 @216.73.216.239
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)