def test_multithreaded_put_complete(num_threads): def callback(pvname, data): result.append(data) def thread(thread_idx): pv.put(thread_idx, callback=callback, callback_data=dict(data=thread_idx), wait=True) time.sleep(0.1) result = [] ca.use_initial_context() pv = get_pv(pvnames.double_pv) threads = [ ca.CAThread(target=thread, args=(i, )) for i in range(num_threads) ] with no_simulator_updates(): for thread in threads: thread.start() for thread in threads: thread.join() assert len(result) == num_threads print(result) assert set(result) == set(range(num_threads))
def test_multithreaded_get(num_threads, thread_class): def thread(thread_idx): result[thread_idx] = ( pv.get(), pv.get_with_metadata(form='ctrl')['value'], pv.get_with_metadata(form='time')['value'], ) result = {} ca.use_initial_context() pv = get_pv(pvnames.double_pv) threads = [ thread_class(target=thread, args=(i, )) for i in range(num_threads) ] with no_simulator_updates(): for thread in threads: thread.start() for thread in threads: thread.join() assert len(result) == num_threads print(result) values = set(result.values()) assert len(values) != 0 value, = values assert value is not None
def test_multithreaded_get(num_threads, thread_class): def thread(thread_idx): result[thread_idx] = (pv.get(), pv.get_with_metadata(form='ctrl')['value'], pv.get_with_metadata(form='time')['value'], ) result = {} ca.use_initial_context() pv = PV(pvnames.double_pv) threads = [thread_class(target=thread, args=(i, )) for i in range(num_threads)] with no_simulator_updates(): for thread in threads: thread.start() for thread in threads: thread.join() assert len(result) == num_threads print(result) values = set(result.values()) assert len(values) == 1 value, = values assert value is not None
def test_multithreaded_put_complete(num_threads): def callback(pvname, data): result.append(data) def thread(thread_idx): pv.put(thread_idx, callback=callback, callback_data=dict(data=thread_idx), wait=True) time.sleep(0.1) result = [] ca.use_initial_context() pv = PV(pvnames.double_pv) threads = [ca.CAThread(target=thread, args=(i, )) for i in range(num_threads)] with no_simulator_updates(): for thread in threads: thread.start() for thread in threads: thread.join() assert len(result) == num_threads print(result) assert set(result) == set(range(num_threads))
def _run(self): ca.use_initial_context() self._periodic_loop(self.update_rate, self._task)