def test_limited_size(execmodel): pool = WorkerPool(execmodel, size=1) q = execmodel.queue.Queue() q2 = execmodel.queue.Queue() q3 = execmodel.queue.Queue() def first(): q.put(1) q2.get() pool.spawn(first) assert q.get() == 1 def second(): q3.put(3) # we spawn a second pool to spawn the second function # which should block pool2 = WorkerPool(execmodel) pool2.spawn(pool.spawn, second) assert not pool2.waitall(1.0) assert q3.qsize() == 0 q2.put(2) assert pool2.waitall() assert pool.waitall()
def test_primary_thread_integration_shutdown(execmodel): if execmodel.backend != "thread": pytest.skip("can only run with threading") pool = WorkerPool(execmodel=execmodel, hasprimary=True) queue = execmodel.queue.Queue() def do_integrate(): queue.put(execmodel.get_ident()) pool.integrate_as_primary_thread() execmodel.start(do_integrate) queue.get() queue2 = execmodel.queue.Queue() def get_two(): queue.put(execmodel.get_ident()) queue2.get() reply = pool.spawn(get_two) # make sure get_two is running and blocked on queue2 queue.get() # then shut down pool.trigger_shutdown() # and let get_two finish queue2.put(1) reply.get() assert pool.waitall(5.0)