Created
April 30, 2019 16:54
-
-
Save waynew/b577271e575cc97370b175af406def26 to your computer and use it in GitHub Desktop.
Fun Thread-a-licious
This file contains 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 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'[s[{lines}A\rHey Dude - {count:>2}\n[u', 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that there are some escape literals in there, so make sure you download the raw file.