How to get Kernel Thread ID in Python 2.7?

48 views Asked by At

I have read in Python version > 3.8 there is function "get_native_id()" in module "threading" to get kernel Thread ID.

Is there any similar possibility to get kernel thread id in Python 2.7?

1

There are 1 answers

1
Guapi-zh On

In Python 2.7, there isn't a built-in function like "get_native_id()" in the threading module to directly obtain the kernel thread ID. The threading module in Python 2.7 provides a high-level interface for working with threads, but it doesn't expose low-level details like the kernel thread ID.

To obtain the kernel thread ID in Python 2.7, you would typically need to use platform-specific code or modules outside of the standard library, and it may not be straightforward. On Unix-based systems (Linux, macOS), you can use the "ctypes" module to access the "pthread_self" function, which returns the thread ID. However, this approach is platform-specific and not recommended unless you have a compelling reason to work at this low level.