def test_multiple_ctx_map(self): # test whether two context pools will interfere with each other pool = CtxPool(processes=2, worker_contexts=[0, 1]) pool2 = CtxPool(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()
def test_ctx_map(self): pool = CtxPool(processes=2, worker_contexts=[0, 1]) # make sure both workers will have items 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()