-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support "become" to initialize actors with circular dependencies #38
Comments
In addition to Unfortunately, it's not really feasible with a standard I believe, it can be implemented with using def tell(self, message):
"""
Send message to actor without waiting for any response.
Will generally not block, but if the underlying queue is full it will
block until a free slot is available.
:param message: message to send
:type message: any
:raise: :exc:`pykka.ActorDeadError` if actor is not available
:return: nothing
"""
if not self.is_alive():
raise ActorDeadError(f"{self} not found")
if isinstance(message, (list_of_control_message_types)):
priority=0
else:
priority=2
self.actor_inbox.put((priority, Envelope(message)))
I took a look into Akka and found out that it stashes not the message content but the message Envelope itself. In Pykka it's possible to have a 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()
self.current_message = envelope
try:
response = self._handle_receive(envelope.message)
if envelope.reply_to is not None:
envelope.reply_to.set(response)
... And to implement stash and unstash_all like this: actor_message_stash: deque = deque()
def _stash(self):
self.actor_message_stash.append(self.current_message)
def _unstash_all(self):
while self.actor_messages_stash:
envelope = self.actor_messages_stash.popleft()
self.actor_inbox.put((1, envelope)) I believe (I should try it for sure), it will allow us to use I'll try it and post later whether this approach works or not. |
It works perfectly for Unfortunately, stashing doesn't really work for
Akka in this case returns a future whose value can be received and processed later and that doesn't lead to exceptions or deadlocks if we don't try to do something silly like I'll check later what happens when we try to use |
Is it possible to provide support for "become" functionality in akka?
See:
http://doc.akka.io/docs/akka/snapshot/scala/actors.html#become-unbecome
Seems like python should be particularly well-suited to such "hot-swapping". Thanks!
The text was updated successfully, but these errors were encountered: