javipalanca / spade

Smart Python Agent Development Environment
MIT License
258 stars 98 forks source link

Starting to learn SPADE platform #77

Closed jbmere closed 4 years ago

jbmere commented 4 years ago

Description

I'm just trying to get running a naive agent according to the provide example, and I've got some unexpected output. See below

What I Did

from spade import agent class DummyAgent(agent.Agent): async def setup(self): print("Hello World! I'm agent {}".format(str(self.jid))) dummy = DummyAgent("dynrct_r01@apiict00.etsii.upm.es", "XXX") dummy.start() dummy.stop()

The output was:
root@rock64:/home/agent# python3 agent01.py 
Hello World! I'm agent dynrct_r01@apiict00.etsii.upm.es
unhandleable IQ request: from=JID(localpart=None, domain='etsii.upm.es', resource=None), type_=<IQType.GET: 'get'>, payload=<aioxmpp.version.xso.Query object at 0x7fa42c2400>

As you can see the last message 'unhandleable ... is unexpected and it makes to never end the script
Do you have any idea about the source for this issue? Any help on how to get it fixed would be really appreciated.
Many thanks in advance
javipalanca commented 4 years ago

The problem is probably that you do the start and stop calls in a row, which are both asynchronous methods. Therefore, you probably stop the agent before the start is finished. My advice is to capture the future that returns start and wait for it:

future = dummy.start()
future.result()

Finally, yo can also use the quit_spade method that ends all the threads safely.

from spade import quit_spade
...
quit_spade()
jbmere commented 4 years ago

Thanks for the hint provided It does help a lot. Now everything works fine