Exemplo n.º 1
0
    def test_subscriber_group(self):
        from multiprocessing import Process, Queue
        from logbook.queues import MultiProcessingHandler, \
                                   MultiProcessingSubscriber, SubscriberGroup
        a_queue = Queue(-1)
        b_queue = Queue(-1)
        test_handler = logbook.TestHandler()
        subscriber = SubscriberGroup([
            MultiProcessingSubscriber(a_queue),
            MultiProcessingSubscriber(b_queue)
        ])

        def make_send_back(message, queue):
            def send_back():
                handler = MultiProcessingHandler(queue)
                handler.push_thread()
                try:
                    logbook.warn(message)
                finally:
                    handler.pop_thread()
            return send_back

        for _ in range(10):
            p1 = Process(target=make_send_back('foo', a_queue))
            p2 = Process(target=make_send_back('bar', b_queue))
            p1.start()
            p2.start()
            p1.join()
            p2.join()
            messages = [subscriber.recv().message for i in 1, 2]
            self.assertEqual(sorted(messages), ['bar', 'foo'])
Exemplo n.º 2
0
def test_subscriber_group():
    from multiprocessing import Process, Queue
    from logbook.queues import MultiProcessingHandler, MultiProcessingSubscriber, SubscriberGroup
    a_queue = Queue(-1)
    b_queue = Queue(-1)
    test_handler = logbook.TestHandler()
    subscriber = SubscriberGroup([
        MultiProcessingSubscriber(a_queue),
        MultiProcessingSubscriber(b_queue)
    ])

    def make_send_back(message, queue):
        def send_back():
            with MultiProcessingHandler(queue):
                logbook.warn(message)
        return send_back

    for _ in range(10):
        p1 = Process(target=make_send_back('foo', a_queue))
        p2 = Process(target=make_send_back('bar', b_queue))
        p1.start()
        p2.start()
        p1.join()
        p2.join()
        messages = [subscriber.recv().message for i in (1, 2)]
        assert sorted(messages) == ['bar', 'foo']
Exemplo n.º 3
0
def test_subscriber_group():
    from multiprocessing import Process, Queue
    from logbook.queues import MultiProcessingSubscriber, SubscriberGroup
    a_queue = Queue(-1)
    b_queue = Queue(-1)
    subscriber = SubscriberGroup([
        MultiProcessingSubscriber(a_queue),
        MultiProcessingSubscriber(b_queue)
    ])

    for _ in range(10):
        p1 = Process(target=SubscriberGroupSendBack('foo', a_queue))
        p2 = Process(target=SubscriberGroupSendBack('bar', b_queue))
        p1.start()
        p2.start()
        p1.join()
        p2.join()
        messages = [subscriber.recv().message for i in (1, 2)]
        assert sorted(messages) == ['bar', 'foo']
Exemplo n.º 4
0
def test_subscriber_group():
    from multiprocessing import Process, Queue
    from logbook.queues import MultiProcessingSubscriber, SubscriberGroup
    a_queue = Queue(-1)
    b_queue = Queue(-1)
    subscriber = SubscriberGroup([
        MultiProcessingSubscriber(a_queue),
        MultiProcessingSubscriber(b_queue)
    ])

    for _ in range(10):
        p1 = Process(target=SubscriberGroupSendBack('foo', a_queue))
        p2 = Process(target=SubscriberGroupSendBack('bar', b_queue))
        p1.start()
        p2.start()
        p1.join()
        p2.join()
        messages = [subscriber.recv().message for i in (1, 2)]
        assert sorted(messages) == ['bar', 'foo']
Exemplo n.º 5
0
def test_subscriber_group():
    if os.getenv('APPVEYOR') == 'True':
        pytest.skip('Test hangs on AppVeyor CI')
    from multiprocessing import Process, Queue
    from logbook.queues import MultiProcessingSubscriber, SubscriberGroup
    a_queue = Queue(-1)
    b_queue = Queue(-1)
    subscriber = SubscriberGroup([
        MultiProcessingSubscriber(a_queue),
        MultiProcessingSubscriber(b_queue)
    ])

    for _ in range(10):
        p1 = Process(target=SubscriberGroupSendBack('foo', a_queue))
        p2 = Process(target=SubscriberGroupSendBack('bar', b_queue))
        p1.start()
        p2.start()
        p1.join()
        p2.join()
        messages = [subscriber.recv().message for i in (1, 2)]
        assert sorted(messages) == ['bar', 'foo']
Exemplo n.º 6
0
def test_subscriber_group():
    if os.getenv('APPVEYOR') == 'True':
        pytest.skip('Test hangs on AppVeyor CI')
    from multiprocessing import Process, Queue
    from logbook.queues import MultiProcessingSubscriber, SubscriberGroup
    a_queue = Queue(-1)
    b_queue = Queue(-1)
    subscriber = SubscriberGroup([
        MultiProcessingSubscriber(a_queue),
        MultiProcessingSubscriber(b_queue)
    ])

    for _ in range(10):
        p1 = Process(target=SubscriberGroupSendBack('foo', a_queue))
        p2 = Process(target=SubscriberGroupSendBack('bar', b_queue))
        p1.start()
        p2.start()
        p1.join()
        p2.join()
        messages = [subscriber.recv().message for i in (1, 2)]
        assert sorted(messages) == ['bar', 'foo']