class STMessenger (object): def __init__(self): self.mqueue = QueueComms() def send_event_update(self, event_list): """Send an event update to the scanning thread. :param event_list: tuple of event name and state :returns: None :raises: ValueError if event_list is mal-formed. """ if isinstance(event_list, tuple) and len(event_list) == 2: self.mqueue.send_to_child(event_list) else: logger.error("Event list: {}".format(event_list)) raise ValueError("Bad event update attempt.") def update_queued(self): """Check is there is an event update waiting to be processed. :returns: True if event waiting """ return self.mqueue.queued_for_child() def get_event_update(self): """Get the next event waiting to be processed. :returns: event_list (may be empty) """ event_list = [] try: event_list = self.mqueue.get_from_child() except Exception: logger.exception("Exception while accessing a child queue.") return event_list def notify_end_of_scan(self): """Notify main thread that scanning thread has terminated. :returns: None """ self.mqueue.signal_parent(1) def check_end_of_scan(self): """ Check to see if the scanning thread as notified us of its termination. :returns: True if termination signal sent. """ return (self.mqueue.get_from_parent() == 1)
def __init__(self): self.mqueue = QueueComms()
class STMessenger(object): def __init__(self): self.mqueue = QueueComms() def send_event_update(self, event_list): """Send an event update to the scanning thread. :param event_list: tuple of event name and state :returns: None :raises: ValueError if event_list is mal-formed. """ if isinstance(event_list, tuple) and len(event_list) == 2: self.mqueue.send_to_child(event_list) else: logger.error("Event list: {}".format(event_list)) raise ValueError("Bad event update attempt.") def update_queued(self): """Check is there is an event update waiting to be processed. :returns: True if event waiting """ return self.mqueue.queued_for_child() def get_event_update(self): """Get the next event waiting to be processed. :returns: event_list (may be empty) """ event_list = [] try: event_list = self.mqueue.get_from_child() except Exception: logger.exception("Exception while accessing a child queue.") return event_list def notify_end_of_scan(self): """Notify main thread that scanning thread has terminated. :returns: None """ self.mqueue.signal_parent(1) def check_end_of_scan(self): """ Check to see if the scanning thread as notified us of its termination. :returns: True if termination signal sent. """ return (self.mqueue.get_from_parent() == 1) def notify_end_of_sync(self): self.mqueue.signal_parent(1) def check_end_of_sync(self): return (self.mqueue.get_from_parent() == 1)