Python threading Module | get_native_id() Method with Example

Python threading.get_native_id() Method: Here, we are going to learn about the getName() method of threading Module in Python with its definition, syntax, and examples.
Submitted by Hritika Rajput, on May 14, 2020

Python threading.get_native_id() Method

get_native_id() is an inbuilt method of the threading module in Python. It is used to return the native Thread ID of the current thread which is assigned by the kernel. This non-negative number can be used to uniquely identify this particular thread system-wide; until the thread terminates, after which its value may be recycled by the OS. It is available from version 3.8.


    import threading




  • None

Return value:

The return type of this method is <class 'int'>, it returns a number that acts as a native thread identifier for the current thread.


# Python program to explain the
# use of get_native_id()  method in Threading Module

import time
import threading

def thread_1(i):
    print("Native thread identifier for Thread-1:", threading.get_native_id())
    print('Value by Thread 1:', i)

def thread_2(i):
    print("Native thread identifier for Thread-2:", threading.get_native_id())
    print('Value by Thread 2:', i)
def thread_3(i):
    print("Native thread identifier for Thread-3:", threading.get_native_id())
    print("Value by Thread 3:", i)

# Creating sample threads 
thread1 = threading.Thread(target=thread_1, args=(10,))
thread2 = threading.Thread(target=thread_2, args=(20,))
thread3 = threading.Thread(target=thread_3, args=(30,))

print("Native thread identifier for main-thread:", threading.get_native_id() )

# Starting the threads


Native thread identifier for main-thread: 19156
Native thread identifier for Thread-2: 4296
Value by Thread 2: 20
Native thread identifier for Thread-3: 6776
Value by Thread 3: 30
Native thread identifier for Thread-1: 17312
Value by Thread 1: 10

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.