def ensure_connected_to_zlog(): """Ensure we are connected to a zlog server. If one is not running and we are the top-level process, start a zlog server configured according to LabConfig.""" global _connected_to_zlog if _connected_to_zlog: return # setup connection with the zlog server: client = ProcessTree.instance().zlog_client if gethostbyname(client.host) == gethostbyname('localhost'): try: # short connection timeout if localhost, don't want to # waste time: client.ping(timeout=0.05) except zmq.ZMQError: # No zlog server running on localhost. Start one. It will run forever, even # after this program exits. This is important for other programs which might # be using it. I don't really consider this bad practice since the server is # typically supposed to be running all the time: start_daemon([sys.executable, '-m', 'labscript_utils.zlog']) # Try again. Longer timeout this time, give it time to start up: client.ping(timeout=15) else: client.ping() _connected_to_zlog = True
import subprocess import types import threading import traceback import datetime import errno import json import labscript_utils.h5_lock import h5py import numpy as np check_version('labscript_utils', '2.12.0', '3') from labscript_utils.ls_zprocess import ProcessTree, zmq_push_multipart from labscript_utils.labconfig import LabConfig process_tree = ProcessTree.instance() __version__ = '2.4.1' def _ensure_str(s): """convert bytestrings and numpy strings to python strings""" return s.decode() if isinstance(s, bytes) else str(s) def mkdir_p(path): try: os.makedirs(path) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(path): pass
os.environ['MPLBACKEND'] = "qt5agg" import lyse from lyse import LYSE_DIR lyse.spinning_top = True import lyse.figure_manager lyse.figure_manager.install() from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar import pylab import labscript_utils.h5_lock, h5py from labscript_utils.modulewatcher import ModuleWatcher process_tree = ProcessTree.connect_to_parent() to_parent = process_tree.to_parent from_parent = process_tree.from_parent kill_lock = process_tree.kill_lock filepath = from_parent.get() # Rename this module to _analysis_subprocess and put it in sys.modules # under that name. The user's analysis routine will become the __main__ module # '_analysis_subprocess'. __name__ = '_analysis_subprocess' sys.modules[__name__] = sys.modules['__main__'] # Set a meaningful client id for zlock process_tree.zlock_client.set_process_name('lyse-' + os.path.basename(filepath))