(self)
The actor's event loop.

        This is the method that will be executed by the thread or greenlet.
The actor's event loop.
The actor s event loop .
def _actor_loop(self):
        """
        The actor's event loop.

        This is the method that will be executed by the thread or greenlet.
        """
        try:
            self.on_start()
        except Exception:
            self._handle_failure(*sys.exc_info())

        while not self.actor_stopped.is_set():
            envelope = self.actor_inbox.get()
            try:
                response = self._handle_receive(envelope.message)
                if envelope.reply_to is not None:
                    envelope.reply_to.set(response)
            except Exception:
                if envelope.reply_to is not None:
                    logger.info(
                        f"Exception returned from {self} to caller:",
                        exc_info=sys.exc_info(),
                    )
                    envelope.reply_to.set_exception()
                else:
                    self._handle_failure(*sys.exc_info())
                    try:
                        self.on_failure(*sys.exc_info())
                    except Exception:
                        self._handle_failure(*sys.exc_info())
            except BaseException:
                exception_value = sys.exc_info()[1]
                logger.debug(f"{exception_value!r} in {self}. Stopping all actors.")
                self._stop()
                ActorRegistry.stop_all()

        while not self.actor_inbox.empty():
            envelope = self.actor_inbox.get()
            if envelope.reply_to is not None:
                if isinstance(envelope.message, messages._ActorStop):
                    envelope.reply_to.set(None)
                else:
                    envelope.reply_to.set_exception(
                        exc_info=(
                            ActorDeadError,
                            ActorDeadError(
                                f"{self.actor_ref} stopped before "
                                f"handling the message"
                            ),
                            None,
                        )
                    )
def _actor_loop ( self ) : try : self . on_start ( ) except Exception : self . _handle_failure ( * sys . exc_info ( ) ) while not self . actor_stopped . is_set ( ) : envelope = self . actor_inbox . get ( ) try : response = self . _handle_receive ( envelope . message ) if envelope . reply_to is not None : envelope . reply_to . set ( response ) except Exception : if envelope . reply_to is not None : logger . info ( f"Exception returned from {self} to caller:" , exc_info = sys . exc_info ( ) , ) envelope . reply_to . set_exception ( ) else : self . _handle_failure ( * sys . exc_info ( ) ) try : self . on_failure ( * sys . exc_info ( ) ) except Exception : self . _handle_failure ( * sys . exc_info ( ) ) except BaseException : exception_value = sys . exc_info ( ) [ 1 ] logger . debug ( f"{exception_value!r} in {self}. Stopping all actors." ) self . _stop ( ) ActorRegistry . stop_all ( ) while not self . actor_inbox . empty ( ) : envelope = self . actor_inbox . get ( ) if envelope . reply_to is not None : if isinstance ( envelope . message , messages . _ActorStop ) : envelope . reply_to . set ( None ) else : envelope . reply_to . set_exception ( exc_info = ( ActorDeadError , ActorDeadError ( f"{self.actor_ref} stopped before " f"handling the message" ) , None , ) )