-
-
Save trivial-search/8026862f4291e4f38e717eb60dd97534 to your computer and use it in GitHub Desktop.
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
try: | |
start_time = datetime.now() | |
#do something endlessly | |
while True: | |
print(datetime.now()) | |
time.sleep(1) | |
# until interrupted by the keyboard | |
except KeyboardInterrupt: | |
#behave gracefully in case of interruption | |
time_lapsed = (datetime.now() - start_time) | |
print('Time elapsed (hh:mm:ss.ms) {}'.format(time_lapsed)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment