Exemple #1
0
    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()
Exemple #2
0
    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:
     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()