def test_subscribe_timeout(): with pytest.raises(TimeoutError): sub = subscribe('__does_not_exit') sub.block() with pytest.raises(TimeoutError): sub = subscribe('__does_not_exit') block(sub)
def init(self): print('init SyncClient') from caproto.sync.client import subscribe self.sub = {} self.token = {} self.sub['period_pv'] = subscribe(self.period_pv_name) self.sub['start_pv'] = subscribe(self.start_pv_name) self.sub['status_pv'] = subscribe(self.status_pv_name) self.token['period_pv'] = self.sub['period_pv'].add_callback(self.monitor) self.token['start_pv'] = self.sub['start_pv'].add_callback(self.monitor) self.token['status_pv'] = self.sub['period_pv'].add_callback(self.monitor) self.sub['period_pv'].block() self.sub['start_pv'].block() self.sub['status_pv'].block()
def fake_kafka(q): sub = subscribe('random_walk:x', data_type='time') def put_into_bus(det_reading): if not pos_readings: # print('no pos readings') return pos_reading = pos_readings[-1] # print(f'x={det_reading.data[0]:.3} pos={pos_reading.data[0]:.3}') q.put((det_reading, pos_reading)) sub.add_callback(put_into_bus) sub.block()
def _run(self): from caproto.sync.client import (read, write, subscribe) if self.acquire: write(self.pvs['enabled'], [1]) write(self.pvs['image_mode'], 'Continuous', data_type=ChannelType.STRING) write(self.pvs['acquire'], [1], notify=False) width = read(self.pvs['array_size0']).data[0] height = read(self.pvs['array_size1']).data[0] depth = read(self.pvs['array_size2']).data[0] color_mode = read(self.pvs['color_mode']).data[0].decode('ascii') bayer_pattern = read(self.pvs['bayer_pattern']) bayer_pattern = bayer_pattern.data[0].decode('ascii') self.new_image_size.emit(width, height, depth, color_mode, bayer_pattern) print(f'width: {width} height: {height} depth: {depth} ' f'color_mode: {color_mode}') def update(response): if self.stop_event.is_set(): raise KeyboardInterrupt native_type = ca.field_types['native'][response.data_type] self.new_image.emit(response.metadata.timestamp, width, height, depth, color_mode, bayer_pattern, native_type, response.data) if self.barrier is not None: # Synchronize with image viewer widget, if necessary self.barrier.wait() sub = subscribe(self.pvs['array_data'], data_type='time') sub.add_callback(update) sub.block() self.stop_event.wait()
def test_subscribe_options(more_kwargs, ioc): args = ('float', ) args = fix_arg_prefixes(ioc, args) sub = subscribe(*args) block(sub, duration=0.5, **more_kwargs)