def close(self): """Ends the background threads, and prevent this instance from servicing further queries.""" if globals()['_GLOBAL_DONE'] == 0: globals()['_GLOBAL_DONE'] = 1 self.notifyAll() self.engine.notify() self.unregisterAllServices() mcastsocket.leave_group( self.socket, dns._MDNS_ADDR ) self.socket.close()
def main(ip): """Create a multicast socket, send a message, check it comes back""" port = PORT sock = mcastsocket.create_socket( (ip,port), loop=False ) mcastsocket.join_group( sock, GROUP ) try: payload = query % locals() while True: sock.sendto( payload, 0, (GROUP,PORT)) #print 'Waiting for responses' rs,wr,xs = select.select( [sock],[],[], 20.0 ) if rs: data, addr = sock.recvfrom( 2000 ) handle( sock, data, addr ) return 1 finally: mcastsocket.leave_group( sock, GROUP )