Esempio n. 1
0
 def validate(self):
     """
     Validate the graph.
     """
     errors = []
     for component in self._components.values():
         for port in component.ports:
             try:
                 port.validate()
             except FlowError as e:
                 errors.append(str(e))
     if errors:
         for error in errors:
             logger.error(error)
         raise FlowError("Errors opening ports")
Esempio n. 2
0
    def go(self, resume=False):
        """
        Execute the network
        """
        import gevent

        now = time.time()

        self.active = True
        deadlock_thread = None

        try:
            if resume:
                self.resume()
            else:
                self.initiate()

            if self.deadlock_test_interval:
                deadlock_thread = gevent.spawn(self._test_deadlocks)

            self.wait_for_all()
        except FlowError as e:
            s = "Flow Error :" + str(e)
            logger.info("Network: " + s)
            raise
        finally:
            self.active = False

        if deadlock_thread:
            deadlock_thread.kill()

        duration = time.time() - now
        logger.info("Run complete.  Time: %.02f seconds" % duration)
        logger.info("Counts:")
        logger.info(" creates:        %d", self.creates)
        logger.info(" drops (manual): %d", self.drops)
        logger.info(" drops (old):    %d", self.drop_olds)
        logger.info(" sends:          %d", self.sends)
        logger.info(" receives:       %d", self.receives)

        if self.error is not None:
            logger.error("re-rasing error")
            # throw the exception which caused the network to stop
            raise_with_traceback(self.error)
Esempio n. 3
0
 def _signal_deadlock(self, statuses):
     # FIXME: move error messages into NetworkDeadlock and get rid of this method?
     logger.error("Network has deadlocked")
     for status, objs in statuses:
         logger.error("  {:<13}{{}}".format(status), args=objs)
     raise NetworkDeadlock("Deadlock detected in Network", statuses)
Esempio n. 4
0
    def go(self, resume=False):
        """
        Execute the network
        """
        import gevent

        now = time.time()

        self.active = True
        deadlock_thread = None

        self.remove_listeners()

        for comp in self.graph._components.values():
            for inport in comp.inports:
                if getattr(inport, '_connection', False):
                    if isinstance(inport._connection, Connection):
                        inport._connection.send.event.add_listener(
                            self.send_data)
                        self.connection_listeners.append(inport._connection)
                elif getattr(inport, '_connections', False):
                    for connection in inport._connections:
                        if isinstance(connection, Connection):
                            connection.send.event.add_listener(self.send_data)
                            self.connection_listeners.append(connection)

        try:
            if resume:
                self.resume()
            else:
                self.initiate()

            if self.deadlock_test_interval:
                deadlock_thread = gevent.spawn(self._test_deadlocks)

            self.wait_for_all()
        except FlowError as e:
            s = "Flow Error :" + str(e)
            logger.info("Network: " + s)
            raise
        finally:
            self.active = False

        if deadlock_thread:
            deadlock_thread.kill()

        self.remove_listeners()

        duration = time.time() - now
        logger.info("Run complete.  Time: %.02f seconds" % duration)
        logger.info("Counts:")
        logger.info(" creates:        %d", self.creates)
        logger.info(" drops (manual): %d", self.drops)
        logger.info(" drops (old):    %d", self.drop_olds)
        logger.info(" sends:          %d", self.sends)
        logger.info(" receives:       %d", self.receives)

        if self.error is not None:
            logger.error("re-rasing error")
            # throw the exception which caused the network to stop
            raise_with_traceback(self.error)