示例#1
0
    def recv_main(self, parent_conn):
        while parent_conn.poll(None):
            try:
                (msg, payload) = parent_conn.recv()
            except EOFError:
                return

            logging.debug("RemoteWorkflow.recv_main :: {}".format(msg))

            try:
                if msg == Msg.NEW_WORKFLOW:
                    self.workflow = []
                    for new_item in payload:
                        idx = len(self.workflow)
                        wi = RemoteWorkflowItem()
                        wi.lock.acquire()
                        wi.matplotlib_events = self.matplotlib_events
                        wi.plot_lock = self.plot_lock
                        wi.copy_traits(new_item,
                                       status=lambda t: t is not True)
                        self.workflow.append(wi)

                    for wi in self.workflow:
                        wi.lock.release()

                elif msg == Msg.RUN_ALL:
                    for wi in self.workflow:
                        wi.lock.acquire()

                    for wi in self.workflow:
                        if hasattr(wi.operation, "estimate"):
                            self.exec_q.put((idx - 0.5, (wi, wi.estimate)))

                        self.exec_q.put((idx, (wi, wi.apply)))

                    for wi in self.workflow:
                        wi.lock.release()

                elif msg == Msg.ADD_ITEMS:
                    (idx, new_item) = payload
                    wi = RemoteWorkflowItem()
                    wi.lock.acquire()
                    wi.copy_traits(new_item)
                    wi.matplotlib_events = self.matplotlib_events
                    wi.plot_lock = self.plot_lock

                    self.workflow.insert(idx, wi)
                    self.exec_q.put((idx, (wi, wi.apply)))
                    wi.lock.release()

                elif msg == Msg.REMOVE_ITEMS:
                    idx = payload
                    self.workflow.remove(self.workflow[idx])

                elif msg == Msg.SELECT:
                    idx = payload
                    if idx == -1:
                        self.selected = None
                    else:
                        self.selected = self.workflow[idx]

                elif msg == Msg.UPDATE_OP:
                    (idx, name, new) = payload
                    wi = self.workflow[idx]
                    with wi.lock:
                        if wi.operation.trait(name).status:
                            raise RuntimeError(
                                "Tried to set a remote status trait")

                        if wi.operation.trait(name).fixed:
                            raise RuntimeError(
                                "Tried to set a remote fixed trait")

                        if wi.operation.trait(name).transient:
                            raise RuntimeError(
                                "Tried to set a remote transient trait")

                        wi.operation.trait_set(**{name: new})

                elif msg == Msg.UPDATE_VIEW:
                    (idx, view_id, name, new) = payload
                    wi = self.workflow[idx]
                    try:
                        view = next((x for x in wi.views if x.id == view_id))
                    except StopIteration:
                        logging.warn(
                            "RemoteWorkflow: Couldn't find view {}".format(
                                view_id))
                        continue

                    with wi.lock:
                        if view.trait(name).status:
                            raise RuntimeError(
                                "Tried to set a remote status trait")

                        if view.trait(name).fixed:
                            raise RuntimeError(
                                "Tried to set a remote fixed trait")

                        if view.trait(name).transient:
                            raise RuntimeError(
                                "Tried to set a remote transient trait")

                        view.trait_set(**{name: new})

                elif msg == Msg.CHANGE_CURRENT_VIEW:
                    (idx, view) = payload
                    wi = self.workflow[idx]
                    try:
                        wi.current_view = next(
                            (x for x in wi.views if x.id == view.id))
                    except StopIteration:
                        wi.views.append(view)
                        wi.current_view = view

                elif msg == Msg.CHANGE_CURRENT_PLOT:
                    (idx, plot) = payload
                    wi = self.workflow[idx]
                    wi.current_plot = plot

                elif msg == Msg.ESTIMATE:
                    idx = payload
                    wi = self.workflow[idx]
                    self.exec_q.put((idx - 0.5, (wi, wi.estimate)))

                elif msg == Msg.SHUTDOWN:
                    self.exec_q.put((0, (None, None)))

                elif msg == Msg.EVAL:
                    expr = payload
                    ret = eval(expr)
                    self.message_q.put((Msg.EVAL, ret))

                elif msg == Msg.EXEC:
                    expr = payload
                    exec(expr)

                else:
                    raise RuntimeError("Bad command in the remote workflow")

            except Exception:
                log_exception()
示例#2
0
    def recv_main(self, parent_conn):
        while parent_conn.poll(None):
            try:
                (msg, payload) = parent_conn.recv()
            except EOFError:
                return

            logging.debug("RemoteWorkflow.recv_main :: {}".format(msg))

            try:
                if msg == Msg.NEW_WORKFLOW:
                    self.workflow = []
                    for new_item in payload:
                        wi = RemoteWorkflowItem()
                        wi.lock.acquire()
                        wi.matplotlib_events = self.matplotlib_events
                        wi.plot_lock = self.plot_lock
                        wi.copy_traits(new_item,
                                       status=lambda t: t is not True)
                        self.workflow.append(wi)

                        # load the data from ImportOp.  This should kick off
                        # the chain of handlers to apply the rest of the
                        # operations, too.  manipulate exec_q directly so we
                        # don't run into timing issues; we want this to be run
                        # first.
                        if self.workflow[0] == wi:
                            self.exec_q.put((0, (wi, wi.apply)))

                    for wi in self.workflow:
                        wi.lock.release()

                elif msg == Msg.ADD_ITEMS:
                    (idx, new_item) = payload
                    wi = RemoteWorkflowItem()
                    wi.copy_traits(new_item)
                    wi.matplotlib_events = self.matplotlib_events
                    wi.plot_lock = self.plot_lock

                    self.workflow.insert(idx, wi)

                elif msg == Msg.REMOVE_ITEMS:
                    idx = payload
                    self.workflow.remove(self.workflow[idx])

                elif msg == Msg.SELECT:
                    idx = payload
                    if idx == -1:
                        self.selected = None
                    else:
                        self.selected = self.workflow[idx]

                elif msg == Msg.UPDATE_OP:
                    (idx, new_op, update_type) = payload
                    wi = self.workflow[idx]
                    with wi.lock:
                        wi.operation.copy_traits(
                            new_op,
                            status=lambda t: t is not True,
                            fixed=lambda t: t is not True)

                    wi.operation.changed = update_type

                elif msg == Msg.UPDATE_VIEW:
                    (idx, new_view, update_type) = payload
                    view_id = new_view.id
                    wi = self.workflow[idx]
                    try:
                        view = next((x for x in wi.views if x.id == view_id))
                    except StopIteration:
                        logging.warn(
                            "RemoteWorkflow: Couldn't find view {}".format(
                                view_id))
                        continue

                    with wi.lock:
                        view.copy_traits(new_view,
                                         status=lambda t: t is not True,
                                         fixed=lambda t: t is not True)

                    view.changed = update_type

                elif msg == Msg.CHANGE_CURRENT_VIEW:
                    (idx, view) = payload
                    wi = self.workflow[idx]
                    try:
                        wi.current_view = next(
                            (x for x in wi.views if x.id == view.id))
                    except StopIteration:
                        wi.views.append(view)
                        wi.current_view = view

                    wi.command = "plot"

                elif msg == Msg.CHANGE_CURRENT_PLOT:
                    (idx, plot) = payload
                    wi = self.workflow[idx]
                    wi.current_plot = plot

                elif msg == Msg.CHANGE_DEFAULT_SCALE:
                    new_scale = payload
                    cytoflow.set_default_scale(new_scale)

                elif msg == Msg.ESTIMATE:
                    idx = payload
                    wi = self.workflow[idx]

                    wi.command = "estimate"

                else:
                    raise RuntimeError("Bad command in the remote workflow")

            except Exception:
                log_exception()