Skip to content

Instantly share code, notes, and snippets.

@waynew
Created April 30, 2019 16:54
Show Gist options
  • Save waynew/b577271e575cc97370b175af406def26 to your computer and use it in GitHub Desktop.
Save waynew/b577271e575cc97370b175af406def26 to your computer and use it in GitHub Desktop.
Fun Thread-a-licious
import time
import random
from threading import Thread, currentThread, Event
lines = 1
def show_stuff(evt):
global lines
count = 0
while not evt.is_set():
print(f'[{lines}A\rHey Dude - {count:>2}\n', end='')
count += 1
time.sleep(1)
def main():
global lines
event = Event()
t1 = Thread(target=show_stuff, args=(event,))
print()
t1.start()
data = []
incoming = ''
while incoming != '.':
try:
incoming = input('Something: ')
lines += 1
except (EOFError, KeyboardInterrupt) as e:
incoming = '.'
data.append(incoming)
data.pop()
event.set()
t1.join()
print()
print('You produced this')
print('='*40)
print('\n'.join(data))
if __name__ == '__main__':
main()
@waynew
Copy link
Author

waynew commented Apr 30, 2019

Note that there are some escape literals in there, so make sure you download the raw file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment