Python Glossary Русский

Python 3.8+threadingfunction

threading.get_native_id()

thread introspection

The system identifier the OS kernel gave the current thread (the TID on Linux) — the same number shown by top -H, ps and debuggers.

Syntax

threading.get_native_id()

Unlike get_ident(), this number is visible outside the process: you find the thread by it in a system monitor, under /proc/<pid>/task/ on Linux or in a profiler. On Linux the main thread's value equals the process PID. The number is reused after the thread ends. A worker's value is also in Thread.native_id, but only after start(): before that it is None.

Examples

import threading
print(threading.get_native_id())  # → ? 48213 — номер выдаёт ОС
print(threading.get_native_id() == threading.main_thread().native_id)  # → True
t = threading.Thread(target=lambda: None)
print(t.native_id)  # → None
t.start()
t.join()
print(isinstance(t.native_id, int))  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy