First time here? Check out the FAQ!

Revision history  [back]

It works for me.  I get:

Process to write: 38193
Process to read: 38194
Get 33 from queue.
done

I'm assuming I corrected indentation to what you had originally.  You can use the {;} icon to insert code without it getting munged:

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,))
  pr = Process(target=read, args=(q,))
  pw.start()
  pr.start()
  pw.join()
  pr.terminate()
  print ('done')

If it still does not work for you some more information that "does not work" would be helpful in diagnosing this...

It works for me.  I get:

get:
Process to write: 38193
Process to read: 38194
Get 33 from queue.
done

I'm assuming I corrected indentation to what you had originally.  You can use the {;} icon to insert code without it getting munged:

munged:
from multiprocessing import Process, Queue
import os, time, random
random

def write(q): print ('Process to write: %s' % os.getpid()) a=33 q.put(a) 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) value)

if __name__=='__main__': q = Queue() pw = Process(target=write, args=(q,)) pr = Process(target=read, args=(q,)) pw.start() pr.start() pw.join() pr.terminate() print ('done')

('done')​ If it still does not work for you some more information that "does not work" would be helpful in diagnosing this...