コード例 #1
0
    def __init__(self, filepath, to_parent, from_parent):
        self.to_parent = to_parent
        self.from_parent = from_parent
        self.filepath = filepath

        # Filepath as a unicode string on py3 and a bytestring on py2,
        # so that the right string type can be passed to functions that
        # require the 'native' string type for that python version. On
        # Python 2, encode it with the filesystem encoding.
        if PY2:
            self.filepath_native_string = self.filepath.encode(sys.getfilesystemencoding())
        else:
            self.filepath_native_string = self.filepath
        
        # Add user script directory to the pythonpath:
        sys.path.insert(0, os.path.dirname(self.filepath_native_string))
        
        # Plot objects, keyed by matplotlib Figure object:
        self.plots = {}

        # An object with a method to unload user modules if any have
        # changed on disk:
        self.modulewatcher = ModuleWatcher()
        
        # Start the thread that listens for instructions from the
        # parent process:
        self.mainloop_thread = threading.Thread(target=self.mainloop)
        self.mainloop_thread.daemon = True
        self.mainloop_thread.start()
コード例 #2
0
    def __init__(self, filepath, to_parent, from_parent):
        self.to_parent = to_parent
        self.from_parent = from_parent
        self.filepath = filepath

        # Add user script directory to the pythonpath:
        sys.path.insert(0, os.path.dirname(self.filepath))

        # Create a module for the user's routine, and insert it into sys.modules as the
        # __main__ module:
        self.routine_module = ModuleType('__main__')
        self.routine_module.__file__ = self.filepath
        # Save the dict so we can reset the module to a clean state later:
        self.routine_module_clean_dict = self.routine_module.__dict__.copy()
        sys.modules[self.routine_module.__name__] = self.routine_module

        # Plot objects, keyed by matplotlib Figure object:
        self.plots = {}

        # An object with a method to unload user modules if any have
        # changed on disk:
        self.modulewatcher = ModuleWatcher()

        # Start the thread that listens for instructions from the
        # parent process:
        self.mainloop_thread = threading.Thread(target=self.mainloop)
        self.mainloop_thread.daemon = True
        self.mainloop_thread.start()
    def __init__(self, filepath, to_parent, from_parent):
        self.to_parent = to_parent
        self.from_parent = from_parent
        self.filepath = filepath

        # Add user script directory to the pythonpath:
        sys.path.insert(0, os.path.dirname(self.filepath))

        # Plot objects, keyed by matplotlib Figure object:
        self.plots = {}

        # An object with a method to unload user modules if any have
        # changed on disk:
        self.modulewatcher = ModuleWatcher()

        # Start the thread that listens for instructions from the
        # parent process:
        self.mainloop_thread = threading.Thread(target=self.mainloop)
        self.mainloop_thread.daemon = True
        self.mainloop_thread.start()
コード例 #4
0
    def __init__(self, filepath, to_parent, from_parent):
        self.to_parent = to_parent
        self.from_parent = from_parent
        self.filepath = filepath

        # Filepath as a unicode string on py3 and a bytestring on py2,
        # so that the right string type can be passed to functions that
        # require the 'native' string type for that python version. On
        # Python 2, encode it with the filesystem encoding.
        if PY2:
            self.filepath_native_string = self.filepath.encode(
                sys.getfilesystemencoding())
        else:
            self.filepath_native_string = self.filepath

        # Add user script directory to the pythonpath:
        sys.path.insert(0, os.path.dirname(self.filepath_native_string))

        # Create a module for the user's routine, and insert it into sys.modules as the
        # __main__ module:
        self.routine_module = ModuleType(b'__main__' if PY2 else '__main__')
        self.routine_module.__file__ = self.filepath_native_string
        # Save the dict so we can reset the module to a clean state later:
        self.routine_module_clean_dict = self.routine_module.__dict__.copy()
        sys.modules[self.routine_module.__name__] = self.routine_module

        # Plot objects, keyed by matplotlib Figure object:
        self.plots = {}

        # An object with a method to unload user modules if any have
        # changed on disk:
        self.modulewatcher = ModuleWatcher()

        # Start the thread that listens for instructions from the
        # parent process:
        self.mainloop_thread = threading.Thread(target=self.mainloop)
        self.mainloop_thread.daemon = True
        self.mainloop_thread.start()
                success = self.compile(*data)
                self.to_parent.put(['done', success])
            elif signal == 'quit':
                sys.exit(0)
            else:
                raise ValueError(signal)

    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()


if __name__ == '__main__':
    module_watcher = ModuleWatcher()  # Make sure modified modules are reloaded
    batch_processor = BatchProcessor(to_parent, from_parent, kill_lock)