Skip to content
Snippets Groups Projects
Commit fb8917f2 authored by jkerdreu's avatar jkerdreu
Browse files

- Cleaning up AsyncEngine

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3002 b32b6428-25c9-4566-ad07-03861ab6144f
parent 3a34fb7f
Branches
No related tags found
No related merge requests found
......@@ -55,9 +55,6 @@ class AsyncEngine(core.EngineMixin):
hook = Hook(HookType.stop,func,*args,**kwargs)
self._hooks.append(hook)
def is_running(self):
return self.running_event.is_set()
async def run_hooks(self,hook_type):
hooks = list(filter(lambda hook: hook.type==hook_type,self._hooks))
if len(hooks)!=0:
......@@ -65,16 +62,6 @@ class AsyncEngine(core.EngineMixin):
for h in hooks:
await run_func(h.func,*h.args,**h.kwargs)
def get_loop(self):
if self._loop == None:
logger.debug('New event loop')
self._loop = asyncio.get_event_loop()
return self._loop
def all_tasks(self):
#return list(asyncio.all_tasks(self.get_loop()))
return self._tasks
#####################################################
# timers
#####################################################
......@@ -152,8 +139,29 @@ class AsyncEngine(core.EngineMixin):
logger.error(e)
#####################################################
# Tasks
# Asyncio loop & Tasks
#####################################################
def get_loop(self):
if self._loop == None:
logger.debug('New event loop')
self._loop = asyncio.get_event_loop()
return self._loop
def new_task(self,coro,name=None):
# we maintain a task list, to be able to stop/start the engine
# on demand. needed by HASS
task = self.get_loop().create_task(coro,name=name)
self._tasks.append(task)
task.add_done_callback(self.task_callback)
return task
def task_callback(self, task):
# called when a task ended
self._tasks.remove(task)
def all_tasks(self):
return self._tasks
async def boot_task(self):
self.watchdog_event.clear()
# queue the alive before anything
......@@ -190,6 +198,9 @@ class AsyncEngine(core.EngineMixin):
#####################################################
# start / stop / shutdown
#####################################################
def is_running(self):
return self.running_event.is_set()
def start(self):
if self.is_running():
logger.warning('Engine already started')
......@@ -201,18 +212,6 @@ class AsyncEngine(core.EngineMixin):
self.new_task(self.timer_task(),name='Timers')
self.new_task(console(locals()),name='Console')
def new_task(self,coro,name=None):
# we maintain a task list, to be able to stop/start the engine
# on demand. needed by HASS
task = self.get_loop().create_task(coro,name=name)
self._tasks.append(task)
task.add_done_callback(self.task_callback)
return task
def task_callback(self, task):
# called when a task ended
self._tasks.remove(task)
def setup_alives_timer(self):
# needed on stop-start sequence
if self.process_alives in [t.func for t in self.timers]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment