Python Multiprocessing queue

前端 未结 2 401
一个人的身影
一个人的身影 2021-01-13 03:23

I am populating a queue with a set of jobs that I want to run in parallel and using python\'s multiprocessing module for doing that. Code snippet below:

impo         


        
2条回答
  •  清歌不尽
    2021-01-13 03:59

    The queue is actually geting populated. You need to call queue.get() for each time you put an object to the queue. So you just need to call queue.get() one more time.

    >>> import multiprocessing
    >>> from multiprocessing import Queue
    >>> queue = Queue()
    >>> jobs = [['a', 'b'], ['c', 'd']]
    >>> for job in jobs:
        queue.put(job)
    
    
    >>> queue.get()
    ['a', 'b']
    >>> queue.get()
    ['c', 'd']
    

提交回复
热议问题