Skip to content

Instantly share code, notes, and snippets.

@disconnect3d
Last active June 24, 2018 12:06
Show Gist options
  • Save disconnect3d/bc53644f361247388757 to your computer and use it in GitHub Desktop.
Save disconnect3d/bc53644f361247388757 to your computer and use it in GitHub Desktop.
Simple clock thread written in Python
#!/usr/bin/env python
from __future__ import print_function
import sys
import threading
import time
import datetime
class Clock(threading.Thread):
def __init__(self, countdown_from=100):
self.countdown_from = countdown_from
self._start = None
threading.Thread.__init__(self)
def run(self):
self._start = time.time()
while True:
time_passed = time.time() - self._start
print('\b\b\b\b\b' + datetime.datetime.fromtimestamp(self.countdown_from - time_passed).strftime('%M:%S'), end='')
sys.stdout.flush()
time.sleep(0.1)
c = Clock(120)
c.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment