Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Created April 5, 2024 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miraculixx/0150456dea7d55d73d8ac0807da7092e to your computer and use it in GitHub Desktop.
Save miraculixx/0150456dea7d55d73d8ac0807da7092e to your computer and use it in GitHub Desktop.
drop-in replacmement for time.sleep (python)
def wait(s, delay=1):
"""
drop-in for time.sleep() with status updates and Ctrl-C support
Usage:
for delay in wait(seconds):
print(f'waiting for {delay} seconds')
"""
import time
try:
while s:
yield str(s)
time.sleep(delay)
s -= 1
except KeyboardInterrupt:
pass
@miraculixx
Copy link
Author

I hand-crafted this, then I got curious if ChatGPT could do it, here's how that went

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment