Revision history [back]
Why doesn't Queue work?
from multiprocessing import Process, Queue import os, time, random def write(q): print ('Process to write: %s' % os.getpid()) a=33 q.put(a) def read(q): # It seems that the function doesn't work print ('Process to read: %s' % os.getpid()) while True: value = q.get(True) print ('Get %s from queue.' % value)
if __name__=='__main__':
q = Queue()
pw = Process(target=write, args=(q,)) p
r = Process(target=read, args=(q,))
pw.start()
pr.start()
pw.join()
pr.terminate()
print ('done')
the output:
Process to write: 1880
done
Why doesn't Queue work?
from multiprocessing import Process, Queue import os, time, random def write(q): print ('Process to write: %s' % os.getpid()) a=33 q.put(a) def read(q): # It seems that the function doesn't work print ('Process to read: %s' % os.getpid()) while True: value = q.get(True) print ('Get %s from queue.' % value)
if __name__=='__main__':
q = Queue()
pw = Process(target=write, args=(q,)) p
r = Process(target=read, args=(q,))
pw.start()
pr.start()
pw.join()
pr.terminate()
print ('done')
the output:
Process to write: 1880
done
Why doesn't Queue work?
from multiprocessing import Process, Queue
import Queueimport os, time, random
def randomdef write(q): print ('Process to write: %s' % os.getpid()) a=33
q.put(a)
def read(q):
q.put(a)def read(q): # It seems that the function doesn't work print ('Process to read: %s' % os.getpid()) while True: value = q.get(True) print ('Get %s from queue.' % value)
if value)if __name__=='__main__': q = Queue() pw = Process(target=write, args=(q,)) p
r pr = Process(target=read, args=(q,)) pw.start() pr.start() pw.join() pr.terminate() print ('done')
the output:
Process ('done')the output:Process to write: 1880
done
1880done