Fix queing of restart

This commit is contained in:
Ruben van de Ven 2019-01-25 13:11:00 +01:00
parent 46299d2dac
commit 2a712fb7e1

View file

@ -320,14 +320,22 @@ class HugveyState(object):
self.logger.critical("No event queue to put {}".format(msg))
else:
# Allow for both the Hugvey Command, or the Story handle the event.
self.eventQueue.put_nowait(msg)
self.story.events.append(msg)
self.loop.call_soon_threadsafe(self._queueEvent, msg)
def _queueEvent(self, msg):
self.logger.debug(f"Queue event in hugvey loop: {msg}")
self.eventQueue.put_nowait(msg)
self.story.events.append(msg)
async def handleEvents(self):
self.eventQueue = asyncio.Queue() # start event queue here, to avoid loop issues
while self.command.isRunning.is_set():
event = await self.eventQueue.get()
self.logger.info("Received: {}".format(event))
if event['event'] == 'connection' and not self.isRunning.is_set():
self.restart()
if event['event'] == 'language':
self.setLanguage(event['code'])
@ -434,7 +442,7 @@ class HugveyState(object):
self.logger.info("Start audio stream")
while self.notShuttingDown:
# self.isRunning.wait()
await self.isRunning.wait()
self.logger.info("Start audio stream")
await self.getStreamer().run()