I would like to know if there is how to create two threads, one to ask some number and another to show this number typed in parallel.
from threading import Thread
global result
result = None
class OutPut(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
global result
if result is not None:
print('Number entered was: {}'.format(result))
class Write(Thread):
def __init__(self):
Thread.__init__(self);
def run(self):
global result
user_write = True
while user_write:
num = int(input('Enter a number? '))
result = num
if num == 0:
user_write = False
threadIO = Write()
threadOutPut = OutPut()
arrThread = [threadIO, threadOutPut]
for tH in arrThread:
tH.start()
for t in arrThread:
t.join()
print('===== THREADS OFF =====')
I was trying to do something with this code. The "thread" of asking until it works but showing what was typed doesn't.