How to use the pykka.messages function in pykka

To help you get started, we’ve selected a few pykka 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 jodal / pykka / pykka / _actor.py View on Github external
def _handle_receive(self, message):
        """Handles messages sent to the actor."""
        message = messages._upgrade_internal_message(message)
        if isinstance(message, messages._ActorStop):
            return self._stop()
        if isinstance(message, messages.ProxyCall):
            callee = self._get_attribute_from_path(message.attr_path)
            return callee(*message.args, **message.kwargs)
        if isinstance(message, messages.ProxyGetAttr):
            attr = self._get_attribute_from_path(message.attr_path)
            return attr
        if isinstance(message, messages.ProxySetAttr):
            parent_attr = self._get_attribute_from_path(message.attr_path[:-1])
            attr_name = message.attr_path[-1]
            return setattr(parent_attr, attr_name, message.value)
        return self.on_receive(message)
github jodal / pykka / pykka / _proxy.py View on Github external
def __setattr__(self, name, value):
        """
        Set a field on the actor.

        Blocks until the field is set to check if any exceptions was raised.
        """
        if name == 'actor_ref' or name.startswith('_'):
            return super(ActorProxy, self).__setattr__(name, value)
        attr_path = self._attr_path + (name,)
        message = messages.ProxySetAttr(attr_path=attr_path, value=value)
        return self.actor_ref.ask(message)
github jodal / pykka / pykka / _actor.py View on Github external
def stop(self):
        """
        Stop the actor.

        It's equivalent to calling :meth:`ActorRef.stop` with ``block=False``.
        """
        self.actor_ref.tell(messages._ActorStop())
github jodal / pykka / pykka / _actor.py View on Github external
def _handle_receive(self, message):
        """Handles messages sent to the actor."""
        message = messages._upgrade_internal_message(message)
        if isinstance(message, messages._ActorStop):
            return self._stop()
        if isinstance(message, messages.ProxyCall):
            callee = self._get_attribute_from_path(message.attr_path)
            return callee(*message.args, **message.kwargs)
        if isinstance(message, messages.ProxyGetAttr):
            attr = self._get_attribute_from_path(message.attr_path)
            return attr
        if isinstance(message, messages.ProxySetAttr):
            parent_attr = self._get_attribute_from_path(message.attr_path[:-1])
            attr_name = message.attr_path[-1]
            return setattr(parent_attr, attr_name, message.value)
        return self.on_receive(message)
github jodal / pykka / pykka / _actor.py View on Github external
def _handle_receive(self, message):
        """Handles messages sent to the actor."""
        message = messages._upgrade_internal_message(message)
        if isinstance(message, messages._ActorStop):
            return self._stop()
        if isinstance(message, messages.ProxyCall):
            callee = self._get_attribute_from_path(message.attr_path)
            return callee(*message.args, **message.kwargs)
        if isinstance(message, messages.ProxyGetAttr):
            attr = self._get_attribute_from_path(message.attr_path)
            return attr
        if isinstance(message, messages.ProxySetAttr):
            parent_attr = self._get_attribute_from_path(message.attr_path[:-1])
            attr_name = message.attr_path[-1]
            return setattr(parent_attr, attr_name, message.value)
        return self.on_receive(message)
github jodal / pykka / pykka / _actor.py View on Github external
def _handle_receive(self, message):
        """Handles messages sent to the actor."""
        message = messages._upgrade_internal_message(message)
        if isinstance(message, messages._ActorStop):
            return self._stop()
        if isinstance(message, messages.ProxyCall):
            callee = self._get_attribute_from_path(message.attr_path)
            return callee(*message.args, **message.kwargs)
        if isinstance(message, messages.ProxyGetAttr):
            attr = self._get_attribute_from_path(message.attr_path)
            return attr
        if isinstance(message, messages.ProxySetAttr):
            parent_attr = self._get_attribute_from_path(message.attr_path[:-1])
            attr_name = message.attr_path[-1]
            return setattr(parent_attr, attr_name, message.value)
        return self.on_receive(message)
github jodal / pykka / pykka / _actor.py View on Github external
except Exception:
                        self._handle_failure(*sys.exc_info())
            except BaseException:
                exception_value = sys.exc_info()[1]
                logger.debug(
                    '{!r} in {}. Stopping all actors.'.format(
                        exception_value, self
                    )
                )
                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(
                                '{} stopped before handling the message'.format(
                                    self.actor_ref
                                )
                            ),
                            None,
                        )
github jodal / pykka / pykka / _proxy.py View on Github external
raise AttributeError('{} has no attribute {!r}'.format(self, name))

        if attr_info['callable']:
            if attr_path not in self._callable_proxies:
                self._callable_proxies[attr_path] = CallableProxy(
                    self.actor_ref, attr_path
                )
            return self._callable_proxies[attr_path]
        elif attr_info['traversable']:
            if attr_path not in self._actor_proxies:
                self._actor_proxies[attr_path] = ActorProxy(
                    self.actor_ref, attr_path
                )
            return self._actor_proxies[attr_path]
        else:
            message = messages.ProxyGetAttr(attr_path=attr_path)
            return self.actor_ref.ask(message, block=False)