Hi Kevin,
I hope you are doing fine.
I have a question regarding the send capability of an actor inside receive_msg method.
In the attached example(simple replication of functionality) Actor A has to perform certain operations in a loop and after some time of processing send back the results to sender(actor).
/**
from thespian.actors import ActorSystem, Actor , ActorSystemException, ThespianWatch, WatchMessage
from thespian.troupe import *
import time
class Main:
def trigger(self):
asys = ActorSystem('multiprocTCPBase')
if not asys:
raise ActorSystemException("Not able to define actor system")
parent_actor = asys.createActor(ParentProcess)
res = asys.ask(parent_actor, "msg1")
print(res)
class ParentProcess(Actor):
def receiveMessage(self, msg, sender):
if isinstance(msg,int):
print("****",msg) # <-- receives only 1st message in flow and then all msgs at once when loop ends
else:
a_addr = self.createActor(A)
self.send(a_addr, 30)
class A(Actor):
def receiveMessage(self, msg, sender):
for i in range(0,msg):
time.sleep(3) # <-- processing time it can go upto a min or more
self.send(sender,i)
print("sent",i) # <-- messages sent from this actor every 3 secs but not received by sender after 3 sec interval
Main().trigger()
**/
I have read your response here
https://github.com/kquick/Thespian/issues/19 and I understand that you mentioned , until there is an exit from the
receiveMessage() the asynchronous framework cannot continue to process the send.
But in case a send needs to be done for each value of a loop and to achieve maximum level of parallelism receiver actor should also receive the msgs in same way, is there anything I could change in the attached example code. I might be missing a very small point here.
The expected output of code should be sent from actor A and then receive in ParentProcess, this should happen for each value in loop, but for now it happens for first value and then loop executes completely before sending the msg to ParentProcess.
Also, in the attached example I believe we can leverage troupe functionality.
Let me know if you need anything else to replicate the issue at your end.
Thanks
Vishal