def start(self): """ for back competibility with older SL codes does nothing """ from ubcs_auxiliary.threading import new_thread if not self.running: new_thread(self.run)
def test_threaded_1(self): from numpy import zeros, arange, copy from time import sleep queue = Queue(shape=(4, 3000, 4096), dtype='int16') for i in range(10): arr_in = zeros((1, 3000, 4096), dtype='int16') + i queue.enqueue(arr_in) arr_out = queue.dequeue(1)[-1] self.assertEqual(i, arr_out[0, 0]) from ubcs_auxiliary.threading import new_thread def run(queue): for i in range(100): from time import sleep arr_in = zeros((1, 3000, 4096), dtype='int16') + i queue.enqueue(arr_in) sleep(0.1) new_thread(run, queue) j = 0 arr2 = arange(0, 99) arr = copy(arr2) * 0 while j < 99: if queue.length > 0: arr_out = queue.dequeue(1)[-1] self.assertEqual(j, arr_out[0, 0]) arr[j] = arr_out[0, 0] j += 1 logging.debug(f'dequeue: {j}') sleep(0.03) self.assertEqual((arr == arr2).all(), True)
def save_images(buffer, t=10): sys.path.append( 'z:\\all projects\\aps\\instrumentation\\software\\lauecollect\\') from GigE_camera_client import Camera camera = Camera('MicrofluidicsCamera') camera.exposure_time = 0.001 camera.stream_bytes_per_second = 1392640 from ubcs_auxiliary.threading import new_thread new_thread(save_image_loop, t, buffer, camera)
def save_buffer(root, comments): from ubcs_auxiliary.threading import new_thread lst = [camera_dm34, camera_dm16, camera_dm4] print('started saving to a drive') for item in lst: item.recording_filename = root + item.name + '_' + comments + '.hdf5' new_thread(camera_dm34.record_once, 600) new_thread(camera_dm16.record_once, 600) camera_dm4.record_once(600) print('done saving to a drive')
def monitor(self,response): info(f'----------Threading Client monitor---------') print(f'system monitor received {response}') print(f'response data {response.data}') print(f'self.system = {self.system}') if self.system is not None: print(f'if statement') value = response.data print(f'response data {bytes(response.data)}') print(self.system.io_execute('Nested_Indices', response.data)) new_thread(self.system.io_execute,'Nested_Indices', value)
def create_pumps(): from syringe_pump.device import Device from ubcs_auxiliary.threading import new_thread p1, p3 = Device(), Device() p1.init(1, 25, 100, 'Y', 250) p1.start() p3.init(3, 25, 100, 'Y', 250) p3.start() new_thread(p1.prime(2)) p3.prime(2) return p1, p3
def test_start_new_thread3(): from time import sleep global value value = 0 def func(): global value value = 5 new_thread(func) sleep(0.01) assert value == 5
def test_start_new_thread2(): from time import sleep global sum_value global kwargs_list def func(*args,**kwargs): global sum_value global kwargs_list from numpy import sum sum_value = sum(args) kwargs_list = list(kwargs.keys()) sum_value = None kwargs_list = None new_thread(func,-1,-2,-3,-4,-5,-6, keyword12 = '', keyword22 = 5) while kwargs_list is None: sleep(0.01) assert sum_value == -21 assert kwargs_list == ['keyword12','keyword22']
def start(self): """ starts run() in a separate thread Parameters ---------- Returns ------- Examples -------- >>> device.run_once() """ from ubcs_auxiliary.threading import new_thread new_thread(self.run)
def stop(self): """ stops data acquisition threads """ from ubcs_auxiliary.threading import new_thread new_thread(camera_tc.stop_thread) new_thread(camera_8mm.stop_thread) new_thread(camera_12mm.stop_thread)
async def system_io_execute(self, pv_name, value): """ wrapper used to submit commands to the system code for execution Parameters ---------- pv_name: (string) string name of the PV value: new value for the PV specified in the pv_name field Returns ------- Examples -------- >>> self.system_io_execute(pv_name = 'CMD', value = '[0]') """ from ubcs_auxiliary.threading import new_thread print("@system_io_execute: The {} putter was called with value {}. The system connected is {}".format(pv_name,value,self.system)) if self.system is not None: new_thread(self.system.io_execute,pv_name, value)
def start(self): """ Create a new thread and submits self.run for execution Parameters ---------- Returns ------- Examples -------- >>> device.start() """ from ubcs_auxiliary.threading import new_thread self.threads['running'] = new_thread(self.run)
def test_start_new_thread(): print('1') def func(*args,**kwargs): global sum_value global kwargs_list from numpy import sum sum_value = sum(args) kwargs_list = list(kwargs.keys()) from time import sleep global sum_value global kwargs_list sum_value = None kwargs_list = None thread = new_thread(func,1,2,3,4,5,6 , daemon = True, keyword1 = '', keyword2 = 5) while kwargs_list is None: sleep(0.01) assert sum_value == 21 assert kwargs_list == ['keyword1','keyword2']
def start_recording(self): from ubcs_auxiliary.threading import new_thread new_thread(self.run_recording)
def start(self): from ubcs_auxiliary.threading import start_new_safe_thread as new_thread new_thread(self.run)
def pause(): from ubcs_auxiliary.threading import new_thread new_thread(camera_dm34.pause_acquisition) new_thread(camera_dm4.pause_acquisition) new_thread(camera_dm16.pause_acquisition)
def stop(): from ubcs_auxiliary.threading import new_thread new_thread(camera_dm4.stop_thread) new_thread(camera_dm16.stop_thread) new_thread(camera_dm34.stop_thread)
def start(self): from ubcs_auxiliary.threading import new_thread new_thread(self.run)
def resume(): from ubcs_auxiliary.threading import new_thread new_thread(camera_dm34.resume_acquisition) new_thread(camera_dm4.resume_acquisition) new_thread(camera_dm16.resume_acquisition)
def _start(self): ''' creates a separete thread for server_thread function ''' new_thread(self._run)
def test(N=10, M=19 * 3, disk=1): from ubcs_auxiliary.threading import new_thread arr = (random.rand(1, 3001, 4096) * 4096).astype('int16') new_thread(test_thread, arr, N, M, disk)