Advertisement
nigaky

queue with multiprocessing??

Mar 28th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. from multiprocessing import Process
  2. import time
  3.  
  4. def f(queue):
  5.     queue.insert(0, [42, None, 'hello'])   # queue.push()
  6.  
  7. if __name__ == '__main__':
  8.     queue = []   # using list as queue
  9.     p = Process(target=f, args=(queue,))
  10.     p.start()
  11.  
  12.     # get value from the child
  13.     while True:
  14.         try:
  15.             val = queue.pop()
  16.             break
  17.         except IndexError:  # queue is empty
  18.             time.sleep(0.1)
  19.  
  20.     print(val)   # never reached!
  21.     p.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement