##### 23.2.2.9 Threads In Python

Python scripts can access information about, and manipulate inferior threads controlled by gdb, via objects of the `gdb.InferiorThread` class.

The following thread-related functions are available in the `gdb` module:

— Function: selected_thread

> This function returns the thread object for the selected thread. If there is no selected thread, this will return `None`.

A `gdb.InferiorThread` object has the following attributes:

— Instance Variable of InferiorThread: num

> ID of the thread, as assigned by GDB.

— Instance Variable of InferiorThread: ptid

> ID of the thread, as assigned by the operating system. This attribute is a tuple containing three integers. The first is the Process ID (PID); the second is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID). Either the LWPID or TID may be 0, which indicates that the operating system does not use that identifier.

A `gdb.InferiorThread` object has the following methods:

— Method on InferiorThread: switch

> This changes gdb's currently selected thread to the one represented by this object.

— Method on InferiorThread: is_stopped

> Return a Boolean indicating whether the thread is stopped.

— Method on InferiorThread: is_running

> Return a Boolean indicating whether the thread is running.

— Method on InferiorThread: is_exited

> Return a Boolean indicating whether the thread is exited.