Skip to content

Instantly share code, notes, and snippets.

@Inndy
Created July 30, 2021 15:42
Show Gist options
  • Save Inndy/67429072eec76c7ac7d21ffabef68c43 to your computer and use it in GitHub Desktop.
Save Inndy/67429072eec76c7ac7d21ffabef68c43 to your computer and use it in GitHub Desktop.
import threading
import time
counter = 0
stop = False
def worker():
global counter
while not stop:
print(f'{counter=}')
counter += 1
time.sleep(0.5)
t = threading.Thread(target=worker)
t.start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
print(f'{counter=}')
if input('Recover? (Y/n): ').strip() == 'n':
stop = True
t.join()
break
print('resume!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment