How to use the fysom.FysomError function in fysom

To help you get started, we’ve selected a few fysom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github instana / python-sensor / instana / meter.py View on Github external
def process(self):
        """ Collects, processes & reports metrics """
        try:
            if self.agent.machine.fsm.current == "wait4init":
                # Test the host agent if we're ready to send data
                if self.agent.is_agent_ready():
                    if self.agent.machine.fsm.current != "good2go":
                        self.agent.machine.fsm.ready()
                else:
                    return
        except FysomError:
            logger.debug('Harmless state machine thread disagreement.  Will self-correct on next timer cycle.')
            return

        if self.agent.can_send():
            self.snapshot_countdown = self.snapshot_countdown - 1
            ss = None
            cm = self.collect_metrics()

            if self.snapshot_countdown < 1:
                logger.debug("Sending process snapshot data")
                self.snapshot_countdown = self.SNAPSHOT_PERIOD
                ss = self.collect_snapshot()
                md = copy.deepcopy(cm).delta_data(None)
            else:
                md = copy.deepcopy(cm).delta_data(self.last_metrics)
github AllYarnsAreBeautiful / ayab-desktop / src / main / python / ayab / ayab.py View on Github external
def run(self):
        try:
            self.function(*self.args, **self.kwargs)
        except FysomError as fe:
            logging.error(fe)
        return
github box / ClusterRunner / app / master / build_fsm.py View on Github external
def trigger(self, build_event, __trigger_fail_on_error=True, **kwargs):
        """
        Trigger the specified event to make the state machine transition to a new state.

        :param build_event:
        :type build_event: BuildEvent
        :param __trigger_fail_on_error: Whether to make a recursive call in the case of failure -- this
            exists only for this method's internal use to prevent infinite recursion.
        :type __trigger_fail_on_error: bool
        :param kwargs: Parameters that will be attached to the event which is passed to callbacks
        :type kwargs: dict
        """
        try:
            self._fsm.trigger(build_event, **kwargs)

        except FysomError as ex:
            # Don't raise transition errors; just fail the build.
            self._logger.exception('Error during build state transition.')
            if __trigger_fail_on_error:
                error_msg = 'Error during build state transition. ({}: {})'.format(type(ex).__name__, ex)
                self.trigger(BuildEvent.FAIL, error_msg=error_msg, __trigger_fail_on_error=False)
            else:
                self._logger.critical('Build attempted to move to ERROR state but the transition itself failed!')
github oxplot / fysom / fysom.py View on Github external
def fn(**kwargs):

      if hasattr(self, 'transition'):
        raise FysomError("event %s inappropriate because previous"
                         " transition did not complete" % event)
      if not self.can(event):
        raise FysomError("event %s inappropriate in current state"
                         " %s" % (event, self.current))

      src = self.current
      dst = self._map[event][src]

      class _e_obj(object):
        pass
      e = _e_obj()
      e.fsm, e.event, e.src, e.dst = self, event, src, dst
      for k in kwargs:
        setattr(e, k, kwargs[k])

      if self.current != dst:

fysom

pYthOn Finite State Machine

MIT
Latest version published 3 years ago

Package Health Score

58 / 100
Full package analysis

Similar packages