Exemplo n.º 1
0
def test_join():
    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.terminate()
Exemplo n.º 2
0
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'