Help! "RuntimeError: threads can only be started once"

1,675 views
Skip to first unread message

EriCSN Chang

unread,
Nov 29, 2013, 5:24:39 AM11/29/13
to spade...@googlegroups.com
I'm a college student interested in SPADE agents.
When I run the code in manual to test ReceiveBehav, it turns out this:

Exception in thread ag...@127.0.0.1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 808, in __bootstrap_inner
    self.run()
  File "/usr/local/lib/python2.7/dist-packages/SPADE-2.2.1-py2.7.egg/spade/Agent.py", line 1009, in run
    self._defaultbehaviour.start()
  File "/usr/lib/python2.7/threading.py", line 737, in start
    raise RuntimeError("threads can only be started once")
RuntimeError: threads can only be started once

I don't know how to fix that...


EriCSN Chang

unread,
Dec 4, 2013, 1:21:33 AM12/4/13
to spade...@googlegroups.com
I marked part of the sample code and modified as below:

import spade

class MyAgent(spade.Agent.Agent):
class ReceiveBehav(spade.Behaviour.Behaviour):
"""This behaviour will receive all kind of messages"""
def onStart(self):
print "receiver starting..."

def _process(self):
self.msg = None
print "process starting..."
# Blocking receive for 10 seconds
self.msg = self._receive(True, 5)
print "receive acton ends."
# Check wether the message arrived
if self.msg:
print "I got a message!"
# print self.msg
else:
print "I waited but got no message"

# class AnotherBehav(spade.Behaviour.Behaviour):
# """This behaviour will receive only messages of the 'cooking' ontology"""
# def _process(self):
# self.msg = None
#
# # Blocking receive indefinitely
# self.msg = self._receive(True)
#
# # Check wether the message arrived
# if self.msg:
# print "I got a cooking message!"
# else:
# print "I waited but got no cooking message"

def _setup(self):
# Add the "ReceiveBehav" as the default behaviour
rb = self.ReceiveBehav()
self.setDefaultBehaviour(rb)
# Prepare template for "AnotherBehav"
# cooking_template = spade.Behaviour.ACLTemplate()
# cooking_template.setOntology("cooking")
# mt = spade.Behaviour.MessageTemplate(cooking_template)

# Add the behaviour WITH the template
# self.addBehaviour(rb, None)

if __name__ == "__main__":
a = MyAgent("rece...@127.0.0.1", "secret")
a.start()

It receives messages from platform now, But why not my own informing agent?


EriCSN Chang於 2013年11月29日星期五UTC+8下午6時24分39秒寫道:

Markus Schatten

unread,
Dec 4, 2013, 9:03:05 AM12/4/13
to spade...@googlegroups.com
Hi,

can you paste your informing agent's code here?

All the best,

M.
--
Markus Schatten, PhD
Assistant professor and head of Artificial Intelligence Lab
University of Zagreb
Faculty of Organization and Informatics
Pavlinska 2, 42000 Varazdin, Croatia
http://www.foi.hr/nastavnici/schatten.markus/index.html
http://www.researchgate.net/profile/Markus_Schatten1
http://ai.foi.hr
> --
> 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/groups/opt_out.

EriCSN Chang

unread,
Dec 4, 2013, 9:40:29 AM12/4/13
to spade...@googlegroups.com, markus....@foi.hr
It's almost as same as the sample:

import spade

class MyAgent(spade.Agent.Agent):
class InformBehav(spade.Behaviour.OneShotBehaviour):
def onStart(self):
print "Starting behaviour..."
def _process(self):
#First, form the receiver AID
receiver = spade.AID.aid(name="rece...@127.0.0.1", addresses = ["xmpp://rece...@127.0.0.1"])
#Second, build the message
self.msg = spade.ACLMessage.ACLMessage()
self.msg.setPerformative("inform")
self.msg.setOntology("myOntology")
self.msg.setLanguage("OWL=S")
self.msg.addReceiver(receiver)
self.msg.setContent("Hello World")

#Third, send the message withthe "send" method of the agent
self.myAgent.send(send.msg)

def onEnd(self):
print "Ending..."


def _setup(self):
print "MyAgent starting..."
b = self.InformBehav()
self.addBehaviour(b, None)


if __name__ == "__main__":
a = MyAgent("ag...@127.0.0.1", "secret")
a.start()

Markus Schatten於 2013年12月4日星期三UTC+8下午10時03分05秒寫道:

Markus Schatten

unread,
Dec 4, 2013, 10:33:39 AM12/4/13
to spade...@googlegroups.com
Hi,

I'm confused a bit. I can reproduce this, but don't know why. The
_receive method seems to be blocking regardless of the supplied time
parameter. It just stops if it receives user supplied messages from
the system, but not from other agents... I'm sure it worked just a few
weeks ago... Maybe Javi can help us out here?

All the best,

M.
--
Markus Schatten, PhD
Assistant professor and head of Artificial Intelligence Lab
University of Zagreb
Faculty of Organization and Informatics
Pavlinska 2, 42000 Varazdin, Croatia
http://www.foi.hr/nastavnici/schatten.markus/index.html
http://www.researchgate.net/profile/Markus_Schatten1
http://ai.foi.hr


Markus Schatten

unread,
Dec 4, 2013, 3:27:51 PM12/4/13
to spade...@googlegroups.com
Hi,

I had some more time now to take a better look, the problem is in the
sending agent, e.g. the line:

self.myAgent.send(send.msg)

should be:

self.myAgent.send(self.msg)

All the best,

M.
--
Markus Schatten, PhD
Assistant professor and head of Artificial Intelligence Lab
University of Zagreb
Faculty of Organization and Informatics
Pavlinska 2, 42000 Varazdin, Croatia
http://www.foi.hr/nastavnici/schatten.markus/index.html
http://www.researchgate.net/profile/Markus_Schatten1
http://ai.foi.hr


On Wed, Dec 4, 2013 at 3:40 PM, EriCSN Chang <eric...@gmail.com> wrote:

Javi Palanca

unread,
Dec 5, 2013, 5:33:25 AM12/5/13
to spade...@googlegroups.com
Hello,

Seems I'm late to solve these questions, but Markus fixed them really great :)

Javi

EriCSN Chang

unread,
Dec 5, 2013, 6:27:02 AM12/5/13
to spade...@googlegroups.com, markus....@foi.hr
Oops. That's my bad... The informer works fine now.
Receiver gets the msg now, thanks for your replies. :)

But there's still a problem, the receiver will block the action no matter how many 10 secs passed until getting new message...

Markus Schatten於 2013年12月5日星期四UTC+8上午4時27分51秒寫道:

Markus Schatten於 2013年12月5日星期四UTC+8上午4時27分51秒寫道:

Markus Schatten

unread,
Dec 5, 2013, 2:31:44 PM12/5/13
to spade...@googlegroups.com
Thanks Javi :)

Eric, yes I noticed that as well, I'm not sure why that happens. I
remember it worked fine a few versions ago. Can you reproduce this,
Javi?

All the best,

M.

On 12/5/13, EriCSN Chang <eric...@gmail.com> wrote:
> Oops. That's my bad... The informer works fine now.
> Receiver gets the msg now, thanks for your replies. :)
>
> But there's still a problem, the receiver will block the action no matter
> how many 10 secs passed until getting new message...
>
> Markus Schatten於 2013年12月5日星期四UTC+8上午4時27分51秒寫道:
>>
>> Hi,
>>
>> I had some more time now to take a better look, the problem is in the
>> sending agent, e.g. the line:
>>
>> self.myAgent.send(send.msg)
>>
>> should be:
>>
>> self.myAgent.send(self.msg)
>>
>> All the best,
>>
>> M.
>> --
>> Markus Schatten, PhD
>> Assistant professor and head of Artificial Intelligence Lab
>> University of Zagreb
>> Faculty of Organization and Informatics
>> Pavlinska 2, 42000 Varazdin, Croatia
>> http://www.foi.hr/nastavnici/schatten.markus/index.html
>> http://www.researchgate.net/profile/Markus_Schatten1
>> http://ai.foi.hr
>>
>>
>> On Wed, Dec 4, 2013 at 3:40 PM, EriCSN Chang
>> <eric...@gmail.com<javascript:>>
>> wrote:
>> > It's almost as same as the sample:
>> >
>> > import spade
>> >
>> > class MyAgent(spade.Agent.Agent):
>> > class InformBehav(spade.Behaviour.OneShotBehaviour):
>> > def onStart(self):
>> > print "Starting behaviour..."
>> > def _process(self):
>> > #First, form the receiver AID
>> > receiver = spade.AID.aid(name="rece...@127.0.0.1 <javascript:>",
>> addresses =
>> > ["xmpp://rece...@127.0.0.1 <javascript:>"])
>> > #Second, build the message
>> > self.msg = spade.ACLMessage.ACLMessage()
>> > self.msg.setPerformative("inform")
>> > self.msg.setOntology("myOntology")
>> > self.msg.setLanguage("OWL=S")
>> > self.msg.addReceiver(receiver)
>> > self.msg.setContent("Hello World")
>> >
>> > #Third, send the message withthe "send" method of the agent
>> > self.myAgent.send(send.msg)
>> >
>> > def onEnd(self):
>> > print "Ending..."
>> >
>> >
>> > def _setup(self):
>> > print "MyAgent starting..."
>> > b = self.InformBehav()
>> > self.addBehaviour(b, None)
>> >
>> >
>> > if __name__ == "__main__":
>> > a = MyAgent("ag...@127.0.0.1 <javascript:>", "secret")
>> > email to spade-users...@googlegroups.com <javascript:>.
>> > To post to this group, send email to
>> > spade...@googlegroups.com<javascript:>.
>>
>> > For more options, visit https://groups.google.com/groups/opt_out.
>>
>
> Markus Schatten於 2013年12月5日星期四UTC+8上午4時27分51秒寫道:
>>
>> Hi,
>>
>> I had some more time now to take a better look, the problem is in the
>> sending agent, e.g. the line:
>>
>> self.myAgent.send(send.msg)
>>
>> should be:
>>
>> self.myAgent.send(self.msg)
>>
>> All the best,
>>
>> M.
>> --
>> Markus Schatten, PhD
>> Assistant professor and head of Artificial Intelligence Lab
>> University of Zagreb
>> Faculty of Organization and Informatics
>> Pavlinska 2, 42000 Varazdin, Croatia
>> http://www.foi.hr/nastavnici/schatten.markus/index.html
>> http://www.researchgate.net/profile/Markus_Schatten1
>> http://ai.foi.hr
>>
>>
>> On Wed, Dec 4, 2013 at 3:40 PM, EriCSN Chang
>> <eric...@gmail.com<javascript:>>
>> wrote:
>> > It's almost as same as the sample:
>> >
>> > import spade
>> >
>> > class MyAgent(spade.Agent.Agent):
>> > class InformBehav(spade.Behaviour.OneShotBehaviour):
>> > def onStart(self):
>> > print "Starting behaviour..."
>> > def _process(self):
>> > #First, form the receiver AID
>> > receiver = spade.AID.aid(name="rece...@127.0.0.1 <javascript:>",
>> addresses =
>> > ["xmpp://rece...@127.0.0.1 <javascript:>"])
>> > #Second, build the message
>> > self.msg = spade.ACLMessage.ACLMessage()
>> > self.msg.setPerformative("inform")
>> > self.msg.setOntology("myOntology")
>> > self.msg.setLanguage("OWL=S")
>> > self.msg.addReceiver(receiver)
>> > self.msg.setContent("Hello World")
>> >
>> > #Third, send the message withthe "send" method of the agent
>> > self.myAgent.send(send.msg)
>> >
>> > def onEnd(self):
>> > print "Ending..."
>> >
>> >
>> > def _setup(self):
>> > print "MyAgent starting..."
>> > b = self.InformBehav()
>> > self.addBehaviour(b, None)
>> >
>> >
>> > if __name__ == "__main__":
>> > a = MyAgent("ag...@127.0.0.1 <javascript:>", "secret")
>> > email to spade-users...@googlegroups.com <javascript:>.
>> > To post to this group, send email to
>> > spade...@googlegroups.com<javascript:>.

Sachith Nalaka Muhandiram

unread,
Aug 4, 2017, 11:47:02 PM8/4/17
to spade-users, markus....@foi.hr
I am still getting the error.
This is my sender.py

    class InformBehav(spade.Behaviour.OneShotBehaviour):

def _process(self):
# First, form the receiver AID
receiver = spade.AID.aid(name="receiver",
addresses=["127.0.0.1"])

# Second, build the message
self.msg = spade.ACLMessage.ACLMessage() # Instantiate the message
self.msg.setPerformative("inform") # Set the "inform" FIPA performative
self.msg.setOntology("myOntology") # Set the ontology of the message content
self.msg.setLanguage("OWL-S") # Set the language of the message content
self.msg.addReceiver(receiver) # Add the message receiver
self.msg.setContent("Hello World") # Set the message content

# Third, send the message with the "send" method of the agent
self.myAgent.send(self.msg)

def _setup(self):
print "MyAgent starting . . ."
      b = self.InformBehav()
self.addBehaviour(b, None)

if __name__ == "__main__":
   a = MyAgent("sen...@127.0.0.1", "abs")
a.start()

My receiver.py


import spade

class MyAgent(spade.Agent.Agent):
class ReceiveBehav(spade.Behaviour.Behaviour):
"""This behaviour will receive all kind of messages"""

      def _process(self):
self.msg = None
         
# Blocking receive for 10 seconds
         self.msg = self._receive(True, 10)


# Check wether the message arrived
if self.msg:
print "I got a message!"
         else:
print "I waited but got no message"

   class AnotherBehav(spade.Behaviour.Behaviour):

"""This behaviour will receive only messages of the 'cooking' ontology"""

      def _process(self):
self.msg = None

         # Blocking receive indefinitely
self.msg = self._receive(True)


# Check wether the message arrived
if self.msg:
            print "I got a cooking message!"
else:

print "I waited but got no cooking message"

def _setup(self):
# Add the "ReceiveBehav" as the default behaviour
rb = self.ReceiveBehav()
self.setDefaultBehaviour(rb)

# Prepare template for "AnotherBehav"
      cooking_template = spade.Behaviour.ACLTemplate()
cooking_template.setOntology("cooking")

mt = spade.Behaviour.MessageTemplate(cooking_template)

# Add the behaviour WITH the template
      self.addBehaviour(rb,None)          

if __name__ == "__main__":
aa = MyAgent("rece...@127.0.0.1", "secret")
aa.start()

What am I missing here??
Reply all
Reply to author
Forward
0 new messages