def compile_labscript_with_globals_files_async(labscript_file, globals_files, output_path, stream_port, done_callback): """Same as compile_labscript_with_globals_files, except it launches a thread to do the work and does not return anything. Instead, stderr and stdout will be put to stream_port via zmq push in the multipart message format ['stdout','hello, world\n'] etc. When compilation is finished, the function done_callback will be called a boolean argument indicating success or failure. If you want to receive the data on a zmq socket, do so using a PULL socket created from a labscript_utils.ls_zprocess.Context, or using a labscript_utils.ls_zprocess.ZMQServer. These subclasses will also be configured with the appropriate security settings and will be able to receive the messages.""" try: make_run_file_from_globals_files(labscript_file, globals_files, output_path) thread = threading.Thread( target=compile_labscript_async, args=[labscript_file, output_path, stream_port, done_callback]) thread.daemon = True thread.start() except Exception: error = traceback.format_exc() zmq_push_multipart(stream_port, data=[b'stderr', error.encode('utf-8')]) t = threading.Thread(target=done_callback, args=(False, )) t.daemon = True t.start()
def compile_multishot_async(labscript_file, run_files, stream_port, done_callback): """Compiles labscript_file with run_files. This function is designed to be called in a thread. The stdout and stderr from the compilation will be shovelled into stream_port via zmq push as it spews forth, and when each compilation is complete, done_callback will be called with a boolean argument indicating success. Compilation will stop after the first failure. If you want to receive the data on a zmq socket, do so using a PULL socket created from a labscript_utils.ls_zprocess.Context, or using a labscript_utils.ls_zprocess.ZMQServer. These subclasses will also be configured with the appropriate security settings and will be able to receive the messages.""" compiler_path = os.path.join(os.path.dirname(__file__), 'batch_compiler.py') to_child, from_child, child = process_tree.subprocess( compiler_path, output_redirection_port=stream_port) try: for run_file in run_files: to_child.put(['compile', [labscript_file, run_file]]) while True: signal, data = from_child.get() if signal == 'done': success = data done_callback(data) break if not success: break except Exception: error = traceback.format_exc() zmq_push_multipart(stream_port, data=[b'stderr', error.encode('utf-8')]) to_child.put(['quit', None]) child.communicate() raise to_child.put(['quit', None]) child.communicate()