ThreadInfo

A single thread inside a target process.

from PyMemoryEditor import ThreadInfo

ThreadInfo is a @dataclass(frozen=True) returned by process.get_threads(). Each backend fills in the fields its OS surfaces cheaply; fields left None mean “this platform does not expose that attribute via the API we use”.

Fields

class ThreadInfo(tid, start_address=None, state=None, priority=None, raw=None)
tid: int

Thread identifier. The meaning of `tid` is platform-specific:

  • Linux — POSIX TID. Same namespace as PID; gettid() returns this.

  • Windows — kernel-assigned global thread id (DWORD) from THREADENTRY32.

  • macOS — Mach thread port name from task_threads. Not the BSD pthread id.

start_address: int | None

Reserved for the thread’s entry point. Currently always ``None`` on every platform — none of the backends fetch it, since obtaining it cheaply isn’t possible across Windows/Linux/macOS. Kept as a stable field for forward compatibility.

state: str | None

Short human-readable state — e.g. "R" / "S" on Linux. None when not available.

priority: int | None

Scheduling priority value as reported by the OS. The scale is platform-specific; None when not available.

raw: Any

Underlying platform handle/struct (THREADENTRY32 on Windows, the TID string from /proc/<pid>/task/ on Linux, a Mach port int on macOS). Useful for advanced callers that need to make follow-up OS-specific calls.

Don’t mix tids across platforms

A tid returned on Linux is not comparable to a tid returned on Windows or macOS — they live in different namespaces. The same warning applies to mixing tid and pid values, which only share a namespace on Linux.

Examples

Listing threads

with OpenProcess(process_name="game.exe") as process:
    for thread in process.get_threads():
        print(thread.tid, thread.state, thread.priority)

The main thread shortcut

print("Main thread:", process.main_thread.tid)

process.main_thread returns the thread with the lowest tid — by convention the “main” thread. It returns None if the process has no listable threads (rare; usually means it just exited).

Counting workers

threads = list(process.get_threads())
print(f"{len(threads)} threads running")