Created
July 30, 2021 15:42
-
-
Save Inndy/67429072eec76c7ac7d21ffabef68c43 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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