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')
def test_emptyish_char_waveform_monitor(self): '''a test of a char waveform of length 1 (NORD=1): value "\0" with using auto_monitor ''' with no_simulator_updates(): zerostr = PV(pvnames.char_arr_pv, auto_monitor=True) zerostr.wait_for_connection() zerostr.put([0], wait=True) time.sleep(0.2) self.assertEquals(zerostr.get(as_string=True), '') numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0]) self.assertEquals(zerostr.get(as_string=True, as_numpy=False), '') numpy.testing.assert_array_equal( zerostr.get(as_string=False, as_numpy=False), [0]) zerostr.put([0, 0], wait=True) time.sleep(0.2) self.assertEquals(zerostr.get(as_string=True), '') numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0, 0]) self.assertEquals(zerostr.get(as_string=True, as_numpy=False), '') numpy.testing.assert_array_equal( zerostr.get(as_string=False, as_numpy=False), [0, 0]) zerostr.disconnect()
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')