Last active
June 24, 2018 12:06
-
-
Save disconnect3d/bc53644f361247388757 to your computer and use it in GitHub Desktop.
Simple clock thread written in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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