예제 #1
0
 def test_multiple_ctx_map(self):
     # test whether two context thread pools will interfere with each other
     pool = CtxThreadPool(processes=2, worker_contexts=[0, 1])
     pool2 = CtxThreadPool(processes=2, worker_contexts=[2, 3])
     # create enough work items so that the execution period of two pools
     # will overlap
     x = [i for i in range(50000)]
     result = pool.map(ctx_func, x)
     result2 = pool2.map(ctx_func, x)
     assert sorted([r[1] for r in result]) == x
     assert {r[0] for r in result}.issubset({0, 1})
     assert sorted([r[1] for r in result2]) == x
     assert {r[0] for r in result2}.issubset({2, 3})
     pool.close()
     pool.join()
     pool2.close()
     pool2.join()
예제 #2
0
 def test_map(self):
     pool = CtxThreadPool(processes=2, worker_contexts=[0, 1])
     x = [i for i in range(10)]
     result = pool.map(ctx_func, x)
     assert sorted([r[1] for r in result]) == x
     assert {r[0] for r in result}.issubset({0, 1})
     pool.close()
     pool.join()