我試圖做一個程序,要求用戶輸入和閱讀器功能打印輸入沒有輸入功能阻止閱讀器功能。監控多進程
這裏我可以做什麼
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))
那是什麼辦法,使在第一終端和其他終端閱讀器功能的輸入功能?我的意思是,我可以在不受閱讀器功能干擾的情況下輸入內容。 My Program Looks like
FAQ
問:你爲什麼不刪除打印功能的閱讀器?你的問題解決了!答:我需要監視程序中的進程。
Ps。 :隨時糾正我的語法,因爲我的英語仍然崩潰。
嗯,非常感謝您的回答。它確實有幫助。 –