Python : Delay with time.sleep() function example
It has been a while since I look at Python code. Need to read up a legacy code left by the previous developer and do some minor adjustment to the existing source code.
Basic stuff, nothing to deep or complicated. Just need to introduce delay into the code.
Here is an example on how to use Python's time module to delay execution.
import time
def main():
print("The time is : " + time.strftime("%c"))
time.sleep(10) # delay for 10 seconds
print("After 10 seconds, the time is now : " + time.strftime("%c"))
if __name__ == '__main__':
main()
Sample output :
The time is : Fri Oct 23 09:51:28 2015
After 10 seconds, the time is now : Fri Oct 23 09:51:38 2015
Reference :
See also : Golang : Call a function after some delay(time.Sleep and Tick)
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+10.9k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+8.3k Golang : How to use if, eq and print properly in html template
+7.2k Golang : How to control fmt or log print format?
+11.8k Golang : Find commonalities in two slices or arrays example
+10.5k Golang : How to convert a number to words
+7.6k Golang : Convert octal value to string to deal with leading zero problem
+5.4k Nginx : How to block user agent ?
+4.5k Javascript : Generate random key with specific length
+7.2k Golang : How to generate Code 39 barcode?
+2.6k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+24.8k Golang : Get time.Duration in year, month, week or day
+18k Golang : Print leading(padding) zero or spaces in fmt.Printf?