python Queue模組實現程序間通訊
阿新 • • 發佈:2019-02-08
Queue本身是一個訊息列隊程式,可以通過這個模組來進行程序之間的相互通訊
[Python] syntaxhighlighter_viewsource syntaxhighlighter_copycode?
[Python] syntaxhighlighter_viewsource syntaxhighlighter_copycode?
01020304050607080910111213141516171819202122232425 | from multiprocessing import Process from multiprocessing import Queue import time def write(q): while True : q.put( "www.c0ks.com" ) time.sleep( 1 ) def read(q): while True : str = q.get() if ( str ! = ""): print ( str ) if __name__ = = "__main__" : q = Queue() pw = Process(target = write,args = (q,)) pr = Process(target = read,args = (q,)) pw.start() pr.start() time.sleep( 10 ) # 強制結束子程序 pw.terminate() pr.terminate() |
原文地址:http://www.c0ks.com/thread-5427-1-1.html