event base docstring. response queue exception handling fix

This commit is contained in:
İsmail Başaran 2016-03-30 10:43:38 +03:00
parent cff628e5df
commit f82e7c4f02
2 changed files with 27 additions and 10 deletions

View file

@ -3,6 +3,11 @@
# @author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com> # @author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
class EventBase(): class EventBase():
"""
This is base event class for event management.
"""
listeners = [] listeners = []
def __init__(self): def __init__(self):
@ -10,10 +15,22 @@ class EventBase():
self.listener_events = [] self.listener_events = []
def register_event(self, event_name, callback_func): 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}) self.listener_events.append({'event_name': event_name, 'callback_func': callback_func})
class Event(): 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): def __init__(self, event_name, *callback_args):
for listener in EventBase.listeners: for listener in EventBase.listeners:
for listener_cls in listener.listener_events: for listener_cls in listener.listener_events:

View file

@ -20,14 +20,14 @@ class MessageResponseQueue(threading.Thread):
self.outQueue = outQueue self.outQueue = outQueue
def run(self): def run(self):
try:
while True: while True:
try:
# This item will send response to lider. # This item will send response to lider.
# item must be response message. Response message may be generic message type # item must be response message. Response message may be generic message type
responseMessage = self.outQueue.get(block=True) responseMessage = self.outQueue.get(block=True)
print(responseMessage) self.logger.debug('[MessageResponseQueue] Sending response message to lider. Response Message ' + str(responseMessage))
# Call message manager for response # Call message manager for response
self.messageManager.send_direct_message(responseMessage) self.messageManager.send_direct_message(responseMessage)
# self.outQueue.task_done() # self.outQueue.task_done()
except: except Exception as e:
pass self.logger.error