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
def _on_start_playing(self): self.__play_lock.acquire() self.__interrupt_action = None self._call_with_super_check(self.on_playing) stack.push(self) MONITOR.register_process(self)