Пример #1
0
    def __init__(self, msg, broker_addr="", graphmgr_addr="", checkpoint_addr="", loop=None,
                 library_paths=None):
        super().__init__()

        if loop is None:
            self.app = QtGui.QApplication([])
            loop = QEventLoop(self.app)

        asyncio.set_event_loop(loop)

        self.win = NodeWindow(self)
        self.win.resize(800, 800)

        if msg.node_type == "SourceNode":
            self.node = SourceNode(name=msg.name)
        else:
            if library_paths:
                dirs = set(map(os.path.dirname, library_paths))
                sys.path.extend(dirs)

                for mod in library_paths:
                    mod = os.path.basename(mod)
                    mod = os.path.splitext(mod)[0]
                    mod = importlib.import_module(mod)

                    nodes = [getattr(mod, name) for name in dir(mod) if isNodeClass(getattr(mod, name))]

                    for node in nodes:
                        LIBRARY.addNodeType(node, [(mod.__name__, )])

            self.node = LIBRARY.getNodeType(msg.node_type)(msg.name)

        self.node.restoreState(msg.state)
        self.graphmgr_addr = graphmgr_addr
        self.ctx = zmq.asyncio.Context()

        self.broker = self.ctx.socket(zmq.SUB)
        self.broker.connect(broker_addr)
        self.broker.setsockopt_string(zmq.SUBSCRIBE, msg.name)

        self.checkpoint = self.ctx.socket(zmq.PUB)
        self.checkpoint.connect(checkpoint_addr)

        self.ctrlWidget = self.node.ctrlWidget(self.win)
        self.widget = None

        self.win.setWindowTitle(msg.name)

        with loop:
            loop.run_until_complete(asyncio.gather(self.process(), self.monitor_node_task()))
Пример #2
0
def run_editor_window(broker_addr, graphmgr_addr, checkpoint_addr, load=None, prometheus_dir=None, hutch=None):
    app = QtGui.QApplication([])

    loop = QEventLoop(app)
    asyncio.set_event_loop(loop)

    # Create main window with grid layout
    win = QtGui.QMainWindow()
    win.setWindowTitle('AMI Client')

    # Create flowchart, define input/output terminals
    fc = Flowchart(broker_addr=broker_addr,
                   graphmgr_addr=graphmgr_addr,
                   checkpoint_addr=checkpoint_addr,
                   prometheus_dir=prometheus_dir, hutch=hutch)

    fc.start_prometheus()

    def update_title(filename):
        if filename:
            win.setWindowTitle('AMI Client - ' + filename.split('/')[-1])
        else:
            win.setWindowTitle('AMI Client')

    fc.sigFileLoaded.connect(update_title)
    fc.sigFileSaved.connect(update_title)

    loop.run_until_complete(fc.updateSources(init=True))

    # Add flowchart control panel to the main window
    win.setCentralWidget(fc.widget())
    win.show()

    # Load a flowchart chart into the editor window
    if load:
        fc.loadFile(load)

    try:
        task = asyncio.ensure_future(fc.run())
        loop.run_forever()
    finally:
        if not task.done():
            loop.run_until_complete(fc.widget().clear())
            task.cancel()
        loop.close()
Пример #3
0
def qevent_loop_gbl(qapp):
    with QEventLoop(qapp) as loop:
        yield loop
Пример #4
0
def run_editor_window(broker_addr,
                      graphmgr_addr,
                      checkpoint_addr,
                      load=None,
                      prometheus_dir=None,
                      prometheus_port=None,
                      hutch=None,
                      configure=False):
    subprocess.run(["dmypy", "start"])
    check_file = None
    with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
        f.write("from typing import *\n")
        f.write("from mypy_extensions import TypedDict\n")
        f.write("import numbers\n")
        f.write("import amitypes\n")
        f.write("T = TypeVar('T')\n")
        f.flush()
        check_file = f.name
        subprocess.run(["dmypy", "check", f.name])

    app = QtGui.QApplication([])

    loop = QEventLoop(app)
    asyncio.set_event_loop(loop)

    # Create main window with grid layout
    win = QtGui.QMainWindow()
    title = 'AMI Client'
    if hutch:
        title += f' hutch: {hutch}'
    win.setWindowTitle(title)

    # Create flowchart, define input/output terminals
    fc = Flowchart(broker_addr=broker_addr,
                   graphmgr_addr=graphmgr_addr,
                   checkpoint_addr=checkpoint_addr,
                   prometheus_dir=prometheus_dir,
                   hutch=hutch,
                   configure=configure)

    fc.start_prometheus(prometheus_port)

    def update_title(filename):
        title = 'AMI Client'
        if hutch:
            title += f' hutch: {hutch}'
        if filename:
            title += ' - ' + filename.split('/')[-1]

        win.setWindowTitle(title)

    fc.sigFileLoaded.connect(update_title)
    fc.sigFileSaved.connect(update_title)

    loop.run_until_complete(fc.updateSources(init=True))

    # Add flowchart control panel to the main window
    win.setCentralWidget(fc.widget())
    win.show()

    try:
        task = asyncio.create_task(fc.run(load))
        loop.run_forever()
    finally:
        if not task.done():
            loop.run_until_complete(fc.widget().clear())
            task.cancel()
        loop.close()

    try:
        proc = subprocess.run(["dmypy", "stop"])
        proc.check_returncode()
    except subprocess.CalledProcessError:
        subprocess.run(["dmypy", "kill"])
    finally:
        if check_file:
            os.remove(check_file)
Пример #5
0
    def __init__(self,
                 broker_addr="",
                 profile_addr="",
                 graph_name="graph",
                 loop=None):
        super().__init__()

        if loop is None:
            self.app = QtGui.QApplication([])
            loop = QEventLoop(self.app)

        asyncio.set_event_loop(loop)

        self.ctx = zmq.asyncio.Context()

        if broker_addr:
            self.broker = self.ctx.socket(zmq.SUB)
            self.broker.setsockopt_string(zmq.SUBSCRIBE, 'profiler')
            self.broker.connect(broker_addr)
        else:
            self.broker = None

        self.graph_name = graph_name
        self.profile_addr = profile_addr
        self.profile = self.ctx.socket(zmq.SUB)
        self.profile.setsockopt_string(zmq.SUBSCRIBE, self.graph_name)
        self.task = None

        self.deserializer = Deserializer()
        self.current_version = 0
        self.metadata = {}  # {version : metadata}
        self.parents = set()

        self.heartbeat_data = {}

        self.widget = QtWidgets.QWidget()
        self.layout = QtGui.QGridLayout(self.widget)
        self.widget.setLayout(self.layout)

        self.enabled_nodes = {}
        self.trace_layout = QtGui.QFormLayout(self.widget)
        hbox = QtWidgets.QHBoxLayout(self.widget)
        selectAll = QtWidgets.QPushButton("Select All", self.widget)
        selectAll.clicked.connect(self.selectAll)
        unselectAll = QtWidgets.QPushButton("Unselect All", self.widget)
        unselectAll.clicked.connect(self.unselectAll)
        hbox.addWidget(selectAll)
        hbox.addWidget(unselectAll)
        self.trace_layout.addRow(hbox)
        self.trace_group = WidgetGroup()
        self.trace_group.sigChanged.connect(self.state_changed)
        self.layout.addLayout(self.trace_layout, 0, 0, -1, 1)

        self.graphicsLayoutWidget = pg.GraphicsLayoutWidget()
        self.layout.addWidget(self.graphicsLayoutWidget, 0, 1, -1, -1)

        self.time_per_heartbeat = self.graphicsLayoutWidget.addPlot(row=0,
                                                                    col=0)
        self.time_per_heartbeat.showGrid(True, True)
        self.time_per_heartbeat.setLabel('bottom', "Heartbeat")
        self.time_per_heartbeat.setLabel('left', "Time (Sec)")
        self.time_per_heartbeat_data = collections.defaultdict(
            lambda: np.array([np.nan] * 100))
        self.time_per_heartbeat_traces = {}
        self.time_per_heartbeat_legend = self.time_per_heartbeat.addLegend()

        self.heartbeats_per_second = self.graphicsLayoutWidget.addPlot(row=0,
                                                                       col=1)
        self.heartbeats_per_second.showGrid(True, True)
        self.heartbeats_per_second.setLabel('bottom', "Heartbeat")
        self.heartbeats_per_second.setLabel('left', "Heartbeats/Second")
        self.heartbeats_per_second_data = np.array([np.nan] * 100)
        self.heartbeats_per_second_trace = None

        self.percent_per_heartbeat = self.graphicsLayoutWidget.addPlot(
            row=1, col=0, rowspan=1, colspan=2)
        self.percent_per_heartbeat.showGrid(True, True)
        self.percent_per_heartbeat_trace = None

        self.last_updated = pg.LabelItem(
            parent=self.time_per_heartbeat.getViewBox())
        self.total_heartbeat_time = pg.LabelItem(
            parent=self.percent_per_heartbeat.getViewBox())
        self.heartbeat_per_second = pg.LabelItem(
            parent=self.heartbeats_per_second.getViewBox())

        self.win = ProfilerWindow(self)
        self.win.setWindowTitle('Profiler')
        self.win.setCentralWidget(self.widget)
        self.win.show()

        with loop:
            loop.run_until_complete(
                asyncio.gather(self.process_broker_message(), self.monitor()))