def test_stop(): inqueue = mp.Queue() outqueue = mp.Queue() def double(val): return val * 2 node = Node(double, inqueue, outqueue) node.start() with pytest.raises(queue.Empty): outqueue.get(block=False) inqueue.put(2) assert outqueue.get() == 4 node.stop() node.join() assert node.is_alive() is False
def test_stop_triggers_a_timeout(): inqueue = mp.Queue() outqueue = mp.Queue() def double(val, timeout=None): if timeout: return 'TIMEOUT' return val * 2 node = Node(double, inqueue, outqueue, timeout=1) node.start() inqueue.put(2) assert outqueue.get() == 4 node.stop() node.join() assert node.is_alive() is False assert outqueue.get() == 'TIMEOUT'