Add Time delay in Python | MS (milliseconds), 1 second

You can use a sleep function to add a delay in the execution of a program. You might be thinking about why needed to make your Python program wait for something?

Here is the answer, You needed a time delay in the program if there is a file to upload or download, or for a graphic to load or user interacting.

Python has built-in time the module has a function sleep() that use to suspend execution of the calling thread for however many seconds you specify.


Add Time delay in Python Example

Here is an example of a 5-second delay execution of the next line. You have to import time modules to use sleep function.


Time delay in Python Example

Sleep Time milliseconds – ms

it’s easy, you may know 1 second = 1000 milliseconds. So you have to pass the value in sleep function like that – 1/1000 = .001. You can put a float number in sleep() function.

If you want to make a delay for 100 milliseconds which is 0.1 seconds.

Output: Start: Before sleep
End: After sleep

Python Time Delay in for loop 


Python time delay

Python delay 1 second

it’s easy, put 1 second = 1 value in function.

Read more about – Python sleep function

Do comment if you have any doubts or suggestions on this tutorial.

Note: This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
Python 3.7
All Python Programs are in Python 3, so it may change its different from python 2 or upgraded versions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.