Python sleep() : How to Add Time Delays to Your Code
Table of Contents
Use [Link]()
Build an Uptime Bot
Next Steps
Relax
Table of Contents
1. Use [Link]()
2. Build an Uptime Bot
3. Next Steps
Take a Break
import time
[Link](3)
Take a Break
import time
[Link](3)
Take a Break
Were those really 3 seconds?
Take a Break
Were those really 3 seconds?
Note: Time for a test!
Take a Break
Were those really 3 seconds?
Note: Time for a test!
Next Up: Terminal test time
Take a Break
import time
[Link](3)
Were those really 3 seconds?
Note: Time for a test!
Time It With timeit
import time
[Link](3)
python3 -m timeit -n 3 "import time; [Link](3)"
Time It With timeit
Default n is 1_000_000
You could sleep for half a year
Time It With timeit
Default n is 1_000_000
You could sleep for half a year
Next Up: Build an Uptime Bot
Table of Contents
1. Use [Link]()
2. Build an Uptime Bot
3. Next Steps
Uptime Bot
# uptime_bot.py
import time
import [Link]
def uptime_bot(url):
while True:
try:
[Link](url)
except Exception as e:
print(f"{e}: for {url}")
else:
print(f"{url} is up")
[Link](60)
if __name__ == "__main__":
url = "[Link]
uptime_bot(url)
Uptime Bot
Next Up: Limit Bot Runs
Uptime Bot
# uptime_bot.py
import time
import [Link]
def uptime_bot(url):
while True:
try:
[Link](url)
except Exception as e:
print(f"{e}: for {url}")
else:
print(f"{url} is up")
[Link](60)
if __name__ == "__main__":
url = "[Link]
uptime_bot(url)
Tame Your Bot
# uptime_bot.py
import time
import [Link]
def uptime_bot(url, retries=3):
fails = 0
while fails < retries:
try:
[Link](url)
except Exception as e:
fails += 1
[Link](60)
# Send an Email
if __name__ == "__main__":
url = "[Link]
uptime_bot(url)
Table of Contents
1. Use [Link]()
2. Build an Uptime Bot
3. Next Steps
Next Steps
Send Email Notifications
Deploy Your Script
Sending Emails With Python
Python Web Applications: Deploy Your Script as a Flask App
Next Steps
Send Email Notifications
Deploy Your Script
Next Steps
Send Email Notifications
Deploy Your Script
Next Up: Summary
Python sleep() : How to Add Time Delays to Your Code
Table of Contents
Used [Link]()
Built an Uptime Bot
Learned about Next Steps
Relaxed and refreshed your Brain
Python sleep() : How to Add Time Delays to Your Code
More Use Cases in the Tutorial