Skip to content

How to Use Sleep in Python Script

Advertisement

In Python programming function you can use sleep() function available under time module. This will sleep or delay script execution for the defined number of seconds.

You can use time.sleep(seconds) as per following. The value passed to sleep() function is in second.

Python Delay Example

Let’s create a small script to print current date time every after 5 seconds.

Execute above script on command line. To exit running script press CTRL + C. You will see results something like below

DateTime Fri Sep 28 17:39:50 2018
DateTime Fri Sep 28 17:39:55 2018
DateTime Fri Sep 28 17:40:00 2018
DateTime Fri Sep 28 17:40:05 2018
DateTime Fri Sep 28 17:40:10 2018

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top