Skip to content

Instantly share code, notes, and snippets.

@trivial-search
Last active April 14, 2018 23:59
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 trivial-search/8026862f4291e4f38e717eb60dd97534 to your computer and use it in GitHub Desktop.
Save trivial-search/8026862f4291e4f38e717eb60dd97534 to your computer and use it in GitHub Desktop.
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