Ejemplo n.º 1
0
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 shoveled 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."""
    compiler_path = os.path.join(os.path.dirname(__file__),
                                 'batch_compiler.py')
    to_child, from_child, child = zprocess.subprocess_with_queues(
        compiler_path, 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()
        zprocess.zmq_push_multipart(stream_port, data=['stderr', error])
        to_child.put(['quit', None])
        child.communicate()
        raise
    to_child.put(['quit', None])
    child.communicate()
Ejemplo n.º 2
0
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."""
    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()
        zprocess.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()
Ejemplo n.º 3
0
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 shoveled 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."""
    compiler_path = os.path.join(os.path.dirname(__file__), 'batch_compiler.py')
    to_child, from_child, child = zprocess.subprocess_with_queues(compiler_path, 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()
        zprocess.zmq_push_multipart(stream_port, data=['stderr', error])
        to_child.put(['quit', None])
        child.communicate()
        raise
    to_child.put(['quit', None])
    child.communicate()
Ejemplo n.º 4
0
def compile_labscript_with_globals_files_async(labscript_file, globals_files, output_path, sequence_id_format, notes, 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."""
    try:
        make_run_file_from_globals_files(labscript_file, globals_files, output_path, sequence_id_format, notes)
        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()
        zprocess.zmq_push_multipart(stream_port, data=['stderr', error])
        t = threading.Thread(target=done_callback, args=(False,))
        t.daemon = True
        t.start()