Is there a way to have an actor process its queue without calling shutdown or an ask to the actor? #106
-
Take the following as an example: import pykka
import time
class Foo(pykka.ThreadingActor):
def on_receive(msg):
print(msg)
Foo.start(use_daemon_thread=True)
Foo.start(use_daemon_thread=False)
for i in range(0,2):
pykka.ActorRegistry.broadcast(
f"{i} bar", target_class=Foo)
print(pykka.ActorRegistry.get_all())
time.sleep(3)
print("done") Output
The two registered actors never process their queue. Doing a similar setup in akka with java seems to drive the event consumption without waiting on the future. maybe that is lanaguage specific feature somehow? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for providing a minimal runnable example! That makes it so much easier to help you :-) I read through your example a few days ago but didn't immediately understand why it didn't work, so I didn't respond right away. When I ran each part here step by step in a Python REPL today, I noticed that To figure out what happened inside the actors that dies, I simply turned on basic debug logging, as recommended in the docs: +import logging
+logging.basicConfig(level=logging.DEBUG)
+
import pykka
import time When running this, I get the following output:
From the traceback, we can see that class Foo(pykka.ThreadingActor):
- def on_receive(msg):
+ def on_receive(self, msg):
print(msg) The example now runs as expected:
Since one of the actors is not a daemon thread, it keeps on running even though the main thread has nothing left to do. To make the example exit properly, ask all actors to stop: print("done")
+
+pykka.ActorRegistry.stop_all() Then it runs to completion and exits:
|
Beta Was this translation helpful? Give feedback.
Thanks for providing a minimal runnable example! That makes it so much easier to help you :-)
I read through your example a few days ago but didn't immediately understand why it didn't work, so I didn't respond right away. When I ran each part here step by step in a Python REPL today, I noticed that
print(pykka.ActorRegistry.get_all())
returned alive actors before the broadcast, but the same line executed again after the broadcast showed an empty list, e.g. all actors where dead.To figure out what happened inside the actors that dies, I simply turned on basic debug logging, as recommended in the docs:
W…