def test_get_pool_queue_sizes(self): worker_pool = Pool(processes=4, worker_names='WorkerThread', maxtasksperchild=3) for _ in xrange(12): worker_pool.apply_async(func=delay) pool_sizes = worker_pool.get_pool_queue_sizes() self.assertGreater(pool_sizes['inqueue_size'], 0) self.assertEqual(pool_sizes['outqueue_size'], 0) worker_pool.terminate_join()
def test_output_pool_size(self): worker_pool = Pool(processes=4, worker_names='WorkerThread', maxtasksperchild=3) results = [] for _ in xrange(12): result = worker_pool.apply_async(func=delay) results.append(result) pool_sizes = worker_pool.get_pool_queue_sizes() while pool_sizes['inqueue_size']: pool_sizes = worker_pool.get_pool_queue_sizes() # Give the result handler task inside the pool set the results on the # result instances stored in the results lists time.sleep(1) # There should be no pending tasks in the output queue self.assertEqual(pool_sizes['outqueue_size'], 0) worker_pool.terminate_join()