I try to make a program that request user an input and the reader function print the input without the input function blocking the reader function.
Here what i can do
import multiprocessing as mp
import time
def ProInput(queue):
while True:
if queue.empty():
print("{} waiting an item".format(mp.current_process().name))
else:
item = queue.get()
if(item == 'exit'):
break;
else:
print("{} processing {}".format(mp.current_process().name, item))
time.sleep(1)
def InputRead(queue):
while True:
f = input("Insert your input :")
queue.put(f)
if(f == 'exit'):
break;
print("You insert {} into the system".format(f))
if __name__ == '__main__':
st = time.time()
q = mp.Queue()
OutputSys = mp.Process(target=ProInput, name='Reader', args=(q,))
OutputSys.daemon = True
OutputSys.start()
InputRead(q)
et = time.time()
OutputSys.join()
print('Total running time {}'.format(et-st))
Is that any way to make The Input function in first terminal and the Reader function in the other terminal? I mean, i can give the input without disturbed by the Reader function.My Program Looks like
FAQ
Q : Why you not delete the print function in Reader? Your problem solved!
A : I need to monitor the process in my program.
Ps. : Feel free to correct my grammar, since my English still broken.