python pool apply_async and map_async do not block on full queue

后端 未结 4 1803
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 11:40

I am fairly new to python. I am using the multiprocessing module for reading lines of text on stdin, converting them in some way and writing them into a database. Here\'s a

4条回答
  •  臣服心动
    2020-12-29 12:34

    Not pretty, but you can access the internal queue size and wait until it's below your maximum desired size before adding new items:

    max_pool_queue_size = 20
    
    for i in range(10000):
      pool.apply_async(some_func, args=(...))
    
      while pool._taskqueue.qsize() > max_pool_queue_size:
        time.sleep(1)
    

提交回复
热议问题