Beispiel #1
0
    def play(self):
        """
        Play the process.
        """
        assert not self.__playing, \
            "Cannot execute a process twice simultaneously"

        try:
            try:
                MONITOR.register_process(self)
                with self.__state_lock:
                    self._call_with_super_check(self.on_playing)

                # Keep going until we run out of tasks
                fn = self._next()
                while fn is not None:
                    with self.__state_lock:
                        self._next_transition = None
                        fn()
                    fn = self._next()

            except BaseException as e:
                exc_type, value, tb = sys.exc_info()
                self._perform_fail_noraise(e)
                return
        finally:
            try:
                MONITOR.deregister_process(self)
                self._call_with_super_check(self.on_done_playing)
            except BaseException as e:
                if self.state != ProcessState.FAILED:
                    exc_type, value, tb = sys.exc_info()
                    self._perform_fail_noraise(e)

        return self._outputs
Beispiel #2
0
    def _on_stop_playing(self):
        """
        WARNING: No state changes should be made after this call.
        """
        MONITOR.deregister_process(self)
        stack.pop(self)
        self.__play_lock.release()

        try:
            self._call_with_super_check(self.on_done_playing)
        except BaseException:
            # Only set failed if it hasn't already failed, otherwise
            # we could obscure the real reason
            if self.state != ProcessState.FAILED:
                self._set_and_execute_state(Failed(self, sys.exc_info()))
                raise

        self.__event_helper.fire_event(ProcessListener.on_process_done_playing,
                                       self)
        if self.has_terminated():
            # There will be no more messages so remove the listeners.  Otherwise we
            # may continue to hold references to them and stop them being garbage
            # collected
            self.__event_helper.remove_all_listeners()