Permalink
Browse files

Aiothread is now hidden to behaviours.

  • Loading branch information...
javipalanca committed Jun 29, 2018
1 parent ccf2bd3 commit cc00d95c23aa3bb5554da5ce08bfdbc79f0fcfe5
Showing with 4 additions and 20 deletions.
  1. +1 −1 .travis.yml
  2. +0 −5 spade/agent.py
  3. +2 −13 spade/behaviour.py
  4. +1 −1 tests/test_behaviour.py
View
@@ -19,7 +19,7 @@ addons:
- libxml2-dev
after_success:
- coveralls
- coveralls --ignore-errors
# command to run tests, e.g. python setup.py test
script:
View
@@ -103,7 +103,6 @@ def add_behaviour(self, behaviour, template=None):
:param template: the template to match messages with
:type template: :class:`spade.template.Template`
"""
behaviour.set_aiothread(self.aiothread)
behaviour.set_agent(self)
behaviour.set_template(template)
self.behaviours.append(behaviour)
@@ -227,10 +226,6 @@ def _connect(self): # pragma: no cover
self.stream = self.loop.run_until_complete(aenter)
logger.info(f"Agent {str(self.jid)} connected and authenticated.")
def submit(self, coro):
fut = asyncio.run_coroutine_threadsafe(coro, loop=self.loop)
return fut
def finalize(self):
aexit = self.conn_coro.__aexit__(*sys.exc_info())
asyncio.run_coroutine_threadsafe(aexit, loop=self.loop)
View
@@ -18,7 +18,6 @@ class BehaviourNotFinishedException(Exception):
class Behaviour(object, metaclass=ABCMeta):
def __init__(self):
self._aiothread = None
self.agent = None
self.template = None
self._force_kill = Event()
@@ -28,23 +27,14 @@ def __init__(self):
self.queue = None
def set_aiothread(self, aiothread):
"""
Links the behaviour with the event loop.
Also creates the incoming messages queue.
:param aiothread: the thread with the event loop
:type aiothread: :class:`spade.agent.AioThread`
"""
self._aiothread = aiothread
self.queue = asyncio.Queue(loop=self._aiothread.loop)
def set_agent(self, agent):
"""
links behaviour with its owner agent
:param agent: the agent who owns the behaviour
:type agent: :class:`spade.agent.Agent`
"""
self.agent = agent
self.queue = asyncio.Queue(loop=self.agent.loop)
self.presence = agent.presence
self.web = agent.web
@@ -93,7 +83,7 @@ def start(self):
"""
starts behaviour in the event loop
"""
self._aiothread.submit(self._start())
self.agent.submit(self._start())
async def _start(self):
"""
@@ -369,7 +359,6 @@ def is_valid_transition(self, source, dest):
async def _run(self):
behaviour = self._states[self.current_state]
behaviour.set_aiothread(self._aiothread)
behaviour.set_agent(self.agent)
behaviour.receive = self.receive
logger.info(f"FSM running state {self.current_state}")
View
@@ -18,7 +18,7 @@
STATE_THREE = "STATE_THREE"
def wait_for_event(event, tries=1000, sleep=0.1):
def wait_for_event(event, tries=100, sleep=0.1):
counter = 0
while not event.is_set() and counter < tries:
event.wait(sleep)

0 comments on commit cc00d95

Please sign in to comment.