Skip to content

Instantly share code, notes, and snippets.

@AJamesPhillips
Last active March 5, 2017 15:09
Show Gist options
  • Save AJamesPhillips/bc138b0a6d353d033e392cb39bca3fd9 to your computer and use it in GitHub Desktop.
Save AJamesPhillips/bc138b0a6d353d033e392cb39bca3fd9 to your computer and use it in GitHub Desktop.
import time
import threading
input_thread_values = []
def input_thread():
print('press s and enter to stop...')
global input_thread_values
input_thread_values.append(input())
print('input_thread has got: {}'.format(input_thread_values))
def do_stuff():
t = threading.Thread(target=input_thread)
t.daemon = True # thread dies when main thread (only non-daemon thread) exits.
t.start()
global input_thread_values
while not input_thread_values:
print('sleeping')
time.sleep(1)
print('interrupted: {}'.format(input_thread_values))
do_stuff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment