def compile(self, labscript_file, run_file): self.script_module.__file__ = labscript_file # Save the current working directory before changing it to the location of the # user's script: cwd = os.getcwd() os.chdir(os.path.dirname(labscript_file)) try: # Do not let the modulewatcher unload any modules whilst we're working: with kill_lock, module_watcher.lock: labscript.labscript_init(run_file, labscript_file=labscript_file) with open(labscript_file) as f: code = compile(f.read(), self.script_module.__file__, 'exec', dont_inherit=True) exec(code, self.script_module.__dict__) return True except Exception: traceback_lines = traceback.format_exception(*sys.exc_info()) del traceback_lines[1:2] message = ''.join(traceback_lines) sys.stderr.write(message) return False finally: labscript.labscript_cleanup() os.chdir(cwd) # Reset the script module's namespace: self.script_module.__dict__.clear() self.script_module.__dict__.update(self.script_module_clean_dict)
def compile(self, labscript_file, run_file): # The namespace the labscript will run in: if PY2: path_native_string = labscript_file.encode(sys.getfilesystemencoding()) else: path_native_string = labscript_file sandbox = {'__name__': '__main__', '__file__': path_native_string} try: # Do not let the modulewatcher unload any modules whilst we're working: with kill_lock, module_watcher.lock: labscript.labscript_init(run_file, labscript_file=labscript_file) with open(labscript_file) as f: code = compile(f.read(), os.path.basename(labscript_file), 'exec', dont_inherit=True) exec(code, sandbox) return True except: traceback_lines = traceback.format_exception(*sys.exc_info()) del traceback_lines[1:2] message = ''.join(traceback_lines) sys.stderr.write(message) return False finally: labscript.labscript_cleanup()
def compile(self,labscript_file, run_file): # The namespace the labscript will run in: sandbox = {'__name__':'__main__'} labscript.labscript_init(run_file, labscript_file=labscript_file) try: with kill_lock: execfile(labscript_file,sandbox,sandbox) return True except: traceback_lines = traceback.format_exception(*sys.exc_info()) del traceback_lines[1:2] message = ''.join(traceback_lines) sys.stderr.write(message) return False finally: labscript.labscript_cleanup()
def compile(self, labscript_file, run_file): # The namespace the labscript will run in: sandbox = {'__name__': '__main__'} try: # Do not let the modulewatcher unload any modules whilst we're working: with kill_lock, module_watcher.lock: labscript.labscript_init(run_file, labscript_file=labscript_file) execfile(labscript_file, sandbox, sandbox) return True except: traceback_lines = traceback.format_exception(*sys.exc_info()) del traceback_lines[1:2] message = ''.join(traceback_lines) sys.stderr.write(message) return False finally: labscript.labscript_cleanup()
##################################################################### # # # /singleshot_compiler.py # # # # Copyright 2017, Joint Quantum Institute # # # # This file is part of the program runmanager, in the labscript # # suite (see http://labscriptsuite.org), and is licensed under the # # Simplified BSD License. See the license.txt file in the root of # # the project for the full license. # # # ##################################################################### """A simple program to be called with a labscript file and a shot h5 file (containing globals) as command line arguments. Calls labscript_init() and then executes the user's labscript file.""" import sys labscript_file, h5_file = sys.argv[1:] import labscript labscript.labscript_init(h5_file) sandbox = {'__name__': '__main__'} execfile(labscript_file, sandbox, sandbox)