Exemplo n.º 1
0
def bench_threading_get_speed(pvname,
                              *,
                              initial_value=None,
                              log_level='ERROR'):
    from caproto.threading.client import (PV, SharedBroadcaster, Context as
                                          ThreadingContext)

    shared_broadcaster = SharedBroadcaster()
    context = ThreadingContext(broadcaster=shared_broadcaster,
                               log_level=log_level)

    def threading():
        value = pv.get(use_monitor=False)
        if initial_value is not None:
            assert len(value) == len(initial_value)

    pv = PV(pvname, auto_monitor=False, context=context)
    if initial_value is not None:
        pv.put(initial_value, wait=True)
    yield threading
    logger.debug('Disconnecting threading pv %s', pv)
    pv.disconnect()
    logger.debug('Disconnecting shared broadcaster %s', shared_broadcaster)
    shared_broadcaster.disconnect()
    logger.debug('Done')
Exemplo n.º 2
0
def bench_threading_many_connections(pv_names,
                                     *,
                                     initial_value=None,
                                     log_level='DEBUG'):
    from caproto.threading.client import (PV, SharedBroadcaster, Context as
                                          ThreadingContext)

    shared_broadcaster = SharedBroadcaster()
    context = ThreadingContext(broadcaster=shared_broadcaster,
                               log_level=log_level)

    pvs = []

    def threading():
        nonlocal pvs

        pvs = [
            PV(pvname, auto_monitor=False, context=context)
            for pvname in pv_names
        ]

        while not all(pv.connected for pv in pvs):
            time.sleep(0.01)

    try:
        yield threading
    finally:
        for pv in pvs:
            pv.disconnect()

        shared_broadcaster.disconnect()
    logger.debug('Done')
Exemplo n.º 3
0
def shared_broadcaster(request):
    sb = SharedBroadcaster()
    yield sb
    sb.disconnect()
    assert not sb._command_thread.is_alive()
    assert not sb.selector.thread.is_alive()
    assert not sb._retry_unanswered_searches_thread.is_alive()
Exemplo n.º 4
0
def bench_threading_put_speed(pvname, *, value, log_level='ERROR'):
    from caproto.threading.client import (PV, SharedBroadcaster, Context as
                                          ThreadingContext)

    shared_broadcaster = SharedBroadcaster()
    context = ThreadingContext(broadcaster=shared_broadcaster,
                               log_level=log_level)

    def threading():
        pv.put(value, wait=True)

    pv = PV(pvname, auto_monitor=False, context=context)

    yield threading

    np.testing.assert_array_almost_equal(pv.get(), value)

    logger.debug('Disconnecting threading pv %s', pv)
    pv.disconnect()
    logger.debug('Disconnecting shared broadcaster %s', shared_broadcaster)
    shared_broadcaster.disconnect()
    logger.debug('Done')