How to pause execution of program in Python?

Today, We want to share with you pause in python.In this post we will show you python wait(), hear for Python’s time.sleep() – Pause, Stop, Wait or Sleep your Python Code we will give you demo and example for implement.In this post, we will learn about How To Wait 5 Seconds In Python? with an example.

Correct way to pause a Python program

  1. time.sleep(1) # sleep for 1 seconds
  2. time.sleep(60) # sleep for 1 minute
  3. time.sleep(3600) # sleep for 1 hour

Python’s time.sleep() Syntax


Using Python’s time.sleep()

Example 1:

import time
time.sleep(5.5)    # Pause 5.5 seconds

For Windows only, use:

import os

How can I make a time delay in Python?

import time
time.sleep(5) #delay for 5 seconds
import time

Time delay for infinite loop

import time
while True:
    print("Thi smessage prints each 5 seconds")
    time.sleep(5)   # Delay for 5 seconds

Count down program with sleep

import time
wait = 10
while wait > 0:
    wait = wait - 1

Thread and Sleep

  import time
      from threading import Thread
      class Main_Thread(Thread):
          def run(self):
              for x in range(100, 104):
                  print(x, " - Main Thread")
      class Service_Thread(Thread):
          def run(self):
              for x in range(1, 16):

Accuracy of time.sleep()

import time
sleep_start = time.time()
for cnt in range(0,10):
   time.sleep(1) # 1 sec delay
sleep_end = time.time()
diff = sleep_end - sleep_start
print("Looping time :",diff)

I hope you get an idea about python sleep milliseconds.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment