def __init__(self, peers, listen_port=None): self.peers = peers self.in_event_queue = Queue.Queue() self.subscriptions = {} # Start thread to listen for incoming events if listen_port: self.peers.append(('localhost', listen_port)) self.listener_thread = CommunicationsInterface.listen(self, listen_port) self.listener_thread.daemon = True self.listener_thread.start()
def __init__(self, peers, listen_port=None): """ EventManager constructor. Keyword arguments: peers -- list of peers to connect to when broadcasting events. Each peer is a tuple of the form (hostname, port). listen_port -- Port to listen for incoming events on. If this is not specified, no listener thread will be created and no events will be received. """ self.peers = peers self.in_event_queue = Queue.Queue() self.subscriptions = {} # Start thread to listen for incoming events if listen_port: self.peers.append(('localhost', listen_port)) self.listener_thread = CommunicationsInterface.listen(self, listen_port) self.listener_thread.daemon = True self.listener_thread.start()
def test_listen(self): # listen should return a ListenerThread instance thread = CommunicationsInterface.listen(None, None) self.assertIsInstance(thread, ListenerThread)