python multiprocessing - process hangs on join for large queue

前端 未结 4 1613
攒了一身酷
攒了一身酷 2020-12-14 07:10

I\'m running python 2.7.3 and I noticed the following strange behavior. Consider this minimal example:

from multiprocessing import Process, Queue

def foo(qi         


        
4条回答
  •  难免孤独
    2020-12-14 07:40

    I was trying to .get() an async worker after the pool had closed

    indentation error outside of a with block

    i had this

    with multiprocessing.Pool() as pool:
        async_results = list()
        for job in jobs:
            async_results.append(
                pool.apply_async(
                    _worker_func,
                    (job,),
                )
            )
    # wrong
    for async_result in async_results:
        yield async_result.get()
    

    i needed this

    with multiprocessing.Pool() as pool:
        async_results = list()
        for job in jobs:
            async_results.append(
                pool.apply_async(
                    _worker_func,
                    (job,),
                )
            )
        # right
        for async_result in async_results:
            yield async_result.get()
    

提交回复
热议问题