how does an agent wait until another agent finishes its works ?

30 views
Skip to first unread message

Sarah

unread,
May 17, 2017, 5:24:58 AM5/17/17
to spade-users
Hello,

I implemented a set agents. One is a sender and the others are receivers. I'm working on localhost.

The sender agent sends to all receiver agents to process something and get results.

The following code is a loop for to send a message to all receiver agents :

                   for i in range(0,len(params.rcvAgents)): 
                            #sending message                        
                            msg = spade.ACLMessage.ACLMessage()
                            msg.setPerformative("request")
                            #print 'Sender has sent a message to:\n'+params.rcvAgents[i]+'@'+params.host,['xmpp://'+params.rcvAgents[i]+'@'+params.host]
                            msg.addReceiver(spade.AID.aid(params.rcvAgents[i]+"@"+params.host,["xmpp://"+params.rcvAgents[i]+"@"+params.host]))
                            msg.setContent(predicted_activity)
                            self.myAgent.send(msg)                       
                                                        
                            time.sleep(10)

when i run it, i saw that the sender agent sends a message for example to the first receiver agent and dont wait it to finish its works so it sends immediately to the second receiver agent.
To resolve this problem, i add the instruction " time.sleep(10)" and it works fine. But its takes much time.
May be you have another solution ? how does the sender agent wait until the actual receiver agents finishes its works ?

Thank you for your help

Javi Palanca

unread,
May 17, 2017, 6:36:33 AM5/17/17
to spade...@googlegroups.com
Hi Sarah
The best option to wait for an agent to be done is probably to wait for a message from her.
Tray to make a blocking receive (with or without a timeout) after sending the message.

Sincerely,
Javi


--
You received this message because you are subscribed to the Google Groups "spade-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spade-users...@googlegroups.com.
To post to this group, send email to spade...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sarah

unread,
May 17, 2017, 6:43:02 AM5/17/17
to spade-users
Thank you for your reply

Could you please explain how to make a blocking receive (with or without a timeout) after sending the message ?

How can i do it ?

Javi Palanca

unread,
May 17, 2017, 7:47:50 AM5/17/17
to spade...@googlegroups.com
Sure!
Just use the self._receive(block=True, timeout=timeout_in_seconds)
where timeout_in_seconds is an integer.
Be careful to run the receive method inside a behavior with a proper template defined, otherwise the receive will return quickly with an unexpected message, since an agent is continuously receiving lots of messages from the platform itself.

All the best,
Javi

Gui L

unread,
Oct 4, 2017, 7:25:22 AM10/4/17
to spade-users
Hello to all, im having a similar problem but i would want to send a message from Agent1 to Agent2 only when AgentOne finishes a task. I want to make something similar to a finite State Machine but with several agents in row acting in a sequence. Im using event behaviours to trigger tasks on agents but then they must run a task before sending a triggering message to next agent.

What ideas on implementing this could i get?
Thanx a lot?
Reply all
Reply to author
Forward
0 new messages