How to suspend the calling thread for few seconds in Python?

You can suspend the calling thread for a given time in Python using the sleep method from the time module. It accepts the number of seconds for which you want to put the calling thread on suspension for.

Example

import time
while(True):
print("Prints every 10 seconds")
time.sleep(10)

Output

Prints every 10 seconds
Prints every 10 seconds
Prints every 10 seconds
...

Each of the above statements will be printed every 10 seconds.

Note that this method also supports floating point values so you can also put the calling thread to sleep for fractions of seconds.