How to Use Time Sleep in Python Script?

In Python programming methods you can use sleep() methods available under time stamp big module. This will sleep or suspends(waits) delay source code with script run as well as execution for the determine total number of seconds.The sleep() wait method to delay or suspends (waits) run with execution of the active more thread for a specify total number of seconds. you can also read my prev article for python absolute value.

Python time sleep() Method

You can use simple helpful to syntax of the time.sleep(seconds) as per below sleep milliseconds example. The data value passed to user can sleep() method is in second format.


Below is the simple syntax for sleep() until wait function โˆ’ Get Current Date & Time in Python

Also Read This ๐Ÿ‘‰   How to pause execution of program in Python?


python sleep milliseconds,python sleep in minutes,python sleep stack,stackoverflow python sleep,python sleep until,python sleeping hours,python delay without sleep,raspberry pi python sleep,python wait
python sleep milliseconds

Example 1: Python sleep()

import time
time.sleep(8)  # delays for 8 second
time.sleep(2)  # delays for 2 second
time.sleep(5)  # delays for 5 second
time.sleep(3)  # delays for 3 seconds
time.sleep(60)  # delays for 1 minute

Example 2: Python Delay Example

Now, Letโ€™s make a tiny script current time source sleeping code to display current date time with Sleep every after 8 seconds.

import time
while True:
    print("Good Morning Dear " + time.strftime("%c"))
    time.sleep(8) # delays execution by 8 seconds

and then you can Execute above simple full script on CMD or Terminal command line. To wait and exit your running mode script press simple CTRL + C. You will great time stamp format display outputs something like as a below way

Free Live Chat for Any Issue

Good Morning Dear Mon Apr 25 15:39:50 2021
Good Morning Dear Mon Apr 25 15:39:58 2021
Good Morning Dear Mon Apr 25 15:40:06 2021
Good Morning Dear Mon Apr 25 15:40:14 2021
Good Morning Dear Mon Apr 25 15:40:22 2021

Example 3: Python create a digital clock with current time

import time

while True:
  mypakatime = time.localtime()
  output = time.strftime("%I:%M:%S %p", mypakatime)


01:11:50 AM
01:11:51 AM
01:11:52 AM
01:11:53 AM
01:11:54 AM
... .. ...

Web Programming Tutorials Example with Demo

Read :

Also Read This ๐Ÿ‘‰   PHP sleep delay Function increasing execution time


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about how to sleep in python?.
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.

Rate this post