Skip to content

Instantly share code, notes, and snippets.

@brunomsantiago
Last active June 7, 2023 16:23
Show Gist options
  • Save brunomsantiago/9fc62c761c5a1e0daa93b0d21abe0496 to your computer and use it in GitHub Desktop.
Save brunomsantiago/9fc62c761c5a1e0daa93b0d21abe0496 to your computer and use it in GitHub Desktop.
Python function to block execution until desired timestamp, with countdown
from time import sleep
from datetime import datetime, timedelta
def wait(until,
update_time=1,
waiting_message='Waiting...',
done_message='Done'):
print(waiting_message)
while (
(countdown := until - datetime.now().replace(microsecond=0))
.total_seconds() > 0
):
print(countdown, end='\r')
sleep(update_time)
print(f'{countdown} {done_message}')
_now = datetime.now().replace(microsecond=0)
_until = _now + timedelta(seconds=20)
wait(_until)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment