Timer objects are used to represent actions that need to be scheduled to run after a certain instant of time. These objects get scheduled to run on a separate thread that carries out the action. However, the interval that a timer is initialized with might not be the actual instant when the action was actually performed by the interpreter because it is the responsibility of the thread scheduler to actually schedule the thread corresponding to the timer object. The timer is a sub-class of the Thread class defined in python. It is started by calling the start() function corresponding to the timer explicitly. It is used to return the seconds of the time
Syntax:
time.thread_time()
Return:
seconds
Example: Python program that uses thread_time() function
In this example, we are going to get the thread_time to get the current time of the system in the python programming language.
Python3
# import time module import time # thread_time() demo time.thread_time() |
Output:
3.394032268
Example 2: Python program that executes concurrently by stopping some seconds
So for that in this example, we are going to use time.sleep() method to wait for some time in the middle of the thread_time() function. At first, we are stopping 10 seconds then 2 seconds and again 2 seconds.
Python3
# import time module import time # thread_time() demo print (time.thread_time()) # sleep for 10 seconds time.sleep( 10 ) # thread_time() demo print (time.thread_time()) # sleep for 2 seconds time.sleep( 2 ) # thread_time() demo print (time.thread_time()) # sleep for 2 seconds time.sleep( 2 ) # thread_time() demo print (time.thread_time()) |
Output:
3.53465852 3.535156974 3.535567409 3.535961336