From f82e7c4f02e5d9b184dfcc424f2d7dcde88ac7ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Wed, 30 Mar 2016 10:43:38 +0300 Subject: [PATCH] event base docstring. response queue exception handling fix --- opt/ahenk/base/event/EventBase.py | 17 ++++++++++++++++ .../base/messaging/MessageResponseQueue.py | 20 +++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/opt/ahenk/base/event/EventBase.py b/opt/ahenk/base/event/EventBase.py index 5d10792..e2d3986 100644 --- a/opt/ahenk/base/event/EventBase.py +++ b/opt/ahenk/base/event/EventBase.py @@ -3,6 +3,11 @@ # @author: İsmail BAŞARAN class EventBase(): + + """ + This is base event class for event management. + """ + listeners = [] def __init__(self): @@ -10,10 +15,22 @@ class EventBase(): self.listener_events = [] def register_event(self, event_name, callback_func): + """ + Registers event listener. + Args: + event_name : name of event, user specify event name + callback_func : when an event fire with specified event name this method will call + """ self.listener_events.append({'event_name': event_name, 'callback_func': callback_func}) class Event(): + """ + This is event class. Takes two argument ; + Args: + event_name : name of event. + callback_args : arguments specified by user. This function will transmit args to callback function directly. + """ def __init__(self, event_name, *callback_args): for listener in EventBase.listeners: for listener_cls in listener.listener_events: diff --git a/opt/ahenk/base/messaging/MessageResponseQueue.py b/opt/ahenk/base/messaging/MessageResponseQueue.py index 91312f7..ce6bf22 100644 --- a/opt/ahenk/base/messaging/MessageResponseQueue.py +++ b/opt/ahenk/base/messaging/MessageResponseQueue.py @@ -20,14 +20,14 @@ class MessageResponseQueue(threading.Thread): self.outQueue = outQueue def run(self): - try: while True: - # This item will send response to lider. - # item must be response message. Response message may be generic message type - responseMessage = self.outQueue.get(block=True) - print(responseMessage) - # Call message manager for response - self.messageManager.send_direct_message(responseMessage) - # self.outQueue.task_done() - except: - pass + try: + # This item will send response to lider. + # item must be response message. Response message may be generic message type + responseMessage = self.outQueue.get(block=True) + self.logger.debug('[MessageResponseQueue] Sending response message to lider. Response Message ' + str(responseMessage)) + # Call message manager for response + self.messageManager.send_direct_message(responseMessage) + # self.outQueue.task_done() + except Exception as e: + self.logger.error