16
16
if PY2 :
17
17
str = unicode
18
18
19
+ try :
20
+ from labscript_utils import check_version
21
+ except ImportError :
22
+ raise ImportError ('Require labscript_utils > 2.1.0' )
23
+
19
24
import itertools
20
25
import os
21
26
import sys
30
35
import h5py
31
36
import numpy as np
32
37
33
- import zprocess
38
+ check_version ('labscript_utils' , '2.11.0' , '3' )
39
+ from labscript_utils .ls_zprocess import ProcessTree , zmq_push_multipart
40
+ process_tree = ProcessTree .instance ()
34
41
35
42
__version__ = '2.2.0'
36
43
@@ -681,13 +688,20 @@ def compile_labscript_with_globals_files(labscript_file, globals_files, output_p
681
688
682
689
683
690
def compile_labscript_async (labscript_file , run_file , stream_port , done_callback ):
684
- """Compiles labscript_file with run_file. This function is designed
685
- to be called in a thread. The stdout and stderr from the compilation
686
- will be shoveled into stream_port via zmq push as it spews forth, and
687
- when compilation is complete, done_callback will be called with a
688
- boolean argument indicating success."""
691
+ """Compiles labscript_file with run_file. This function is designed to be called in
692
+ a thread. The stdout and stderr from the compilation will be shovelled into
693
+ stream_port via zmq push as it spews forth, and when compilation is complete,
694
+ done_callback will be called with a boolean argument indicating success. Note that
695
+ the zmq communication will be encrypted, or not, according to security settings in
696
+ labconfig. If you want to receive the data on a zmq socket, do so using a PULL
697
+ socket created from a labscript_utils.ls_zprocess.Context, or using a
698
+ labscript_utils.ls_zprocess.ZMQServer. These subclasses will also be configured
699
+ with the appropriate security settings and will be able to receive the messages.
700
+ """
689
701
compiler_path = os .path .join (os .path .dirname (__file__ ), 'batch_compiler.py' )
690
- to_child , from_child , child = zprocess .subprocess_with_queues (compiler_path , stream_port )
702
+ to_child , from_child , child = process_tree .subprocess (
703
+ compiler_path , output_redirection_port = stream_port
704
+ )
691
705
to_child .put (['compile' , [labscript_file , run_file ]])
692
706
while True :
693
707
signal , data = from_child .get ()
@@ -702,14 +716,19 @@ def compile_labscript_async(labscript_file, run_file, stream_port, done_callback
702
716
703
717
704
718
def compile_multishot_async (labscript_file , run_files , stream_port , done_callback ):
705
- """Compiles labscript_file with run_files. This function is designed
706
- to be called in a thread. The stdout and stderr from the compilation
707
- will be shoveled into stream_port via zmq push as it spews forth,
708
- and when each compilation is complete, done_callback will be called
709
- with a boolean argument indicating success. Compilation will stop
710
- after the first failure."""
719
+ """Compiles labscript_file with run_files. This function is designed to be called in
720
+ a thread. The stdout and stderr from the compilation will be shovelled into
721
+ stream_port via zmq push as it spews forth, and when each compilation is complete,
722
+ done_callback will be called with a boolean argument indicating success. Compilation
723
+ will stop after the first failure. If you want to receive the data on a zmq socket,
724
+ do so using a PULL socket created from a labscript_utils.ls_zprocess.Context, or
725
+ using a labscript_utils.ls_zprocess.ZMQServer. These subclasses will also be
726
+ configured with the appropriate security settings and will be able to receive the
727
+ messages."""
711
728
compiler_path = os .path .join (os .path .dirname (__file__ ), 'batch_compiler.py' )
712
- to_child , from_child , child = zprocess .subprocess_with_queues (compiler_path , stream_port )
729
+ to_child , from_child , child = process_tree .subprocess (
730
+ compiler_path , output_redirection_port = stream_port
731
+ )
713
732
try :
714
733
for run_file in run_files :
715
734
to_child .put (['compile' , [labscript_file , run_file ]])
@@ -723,7 +742,7 @@ def compile_multishot_async(labscript_file, run_files, stream_port, done_callbac
723
742
break
724
743
except Exception :
725
744
error = traceback .format_exc ()
726
- zprocess . zmq_push_multipart (stream_port , data = [b'stderr' , error .encode ('utf-8' )])
745
+ zmq_push_multipart (stream_port , data = [b'stderr' , error .encode ('utf-8' )])
727
746
to_child .put (['quit' , None ])
728
747
child .communicate ()
729
748
raise
@@ -732,12 +751,15 @@ def compile_multishot_async(labscript_file, run_files, stream_port, done_callbac
732
751
733
752
734
753
def compile_labscript_with_globals_files_async (labscript_file , globals_files , output_path , stream_port , done_callback ):
735
- """Same as compile_labscript_with_globals_files, except it launches
736
- a thread to do the work and does not return anything. Instead,
737
- stderr and stdout will be put to stream_port via zmq push in
738
- the multipart message format ['stdout','hello, world\n '] etc. When
739
- compilation is finished, the function done_callback will be called
740
- a boolean argument indicating success or failure."""
754
+ """Same as compile_labscript_with_globals_files, except it launches a thread to do
755
+ the work and does not return anything. Instead, stderr and stdout will be put to
756
+ stream_port via zmq push in the multipart message format ['stdout','hello, world\n ']
757
+ etc. When compilation is finished, the function done_callback will be called a
758
+ boolean argument indicating success or failure. If you want to receive the data on
759
+ a zmq socket, do so using a PULL socket created from a
760
+ labscript_utils.ls_zprocess.Context, or using a
761
+ labscript_utils.ls_zprocess.ZMQServer. These subclasses will also be configured with
762
+ the appropriate security settings and will be able to receive the messages."""
741
763
try :
742
764
make_run_file_from_globals_files (labscript_file , globals_files , output_path )
743
765
thread = threading .Thread (
@@ -746,7 +768,7 @@ def compile_labscript_with_globals_files_async(labscript_file, globals_files, ou
746
768
thread .start ()
747
769
except Exception :
748
770
error = traceback .format_exc ()
749
- zprocess . zmq_push_multipart (stream_port , data = [b'stderr' , error .encode ('utf-8' )])
771
+ zmq_push_multipart (stream_port , data = [b'stderr' , error .encode ('utf-8' )])
750
772
t = threading .Thread (target = done_callback , args = (False ,))
751
773
t .daemon = True
752
774
t .start ()
0 commit comments