Fix signalreceiver when connecting to remote daemons

This commit is contained in:
Andrew Resch 2008-07-19 00:22:50 +00:00
parent 0ccfb483ba
commit f68d4a7896
1 changed files with 10 additions and 3 deletions

View File

@ -58,6 +58,9 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
self.remote = False self.remote = False
self.start_server()
def start_server(self, port=None):
# Setup the xmlrpc server # Setup the xmlrpc server
host = "localhost" host = "localhost"
if self.remote == True: if self.remote == True:
@ -65,17 +68,20 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
server_ready = False server_ready = False
while not server_ready: while not server_ready:
port = random.randint(40000, 65535) if port:
_port = port
else:
_port = random.randint(40000, 65535)
try: try:
SimpleXMLRPCServer.SimpleXMLRPCServer.__init__( SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(
self, (host, port), logRequests=False, allow_none=True) self, (host, _port), logRequests=False, allow_none=True)
except socket.error, e: except socket.error, e:
log.debug("Trying again with another port: %s", e) log.debug("Trying again with another port: %s", e)
except: except:
log.error("Could not start SignalReceiver XMLRPC server: %s", e) log.error("Could not start SignalReceiver XMLRPC server: %s", e)
sys.exit(0) sys.exit(0)
else: else:
self.port = port self.port = _port
server_ready = True server_ready = True
# Register the emit_signal function # Register the emit_signal function
@ -100,6 +106,7 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
def set_remote(self, remote): def set_remote(self, remote):
self.remote = remote self.remote = remote
self.start_server(self.port)
def run(self): def run(self):
"""This gets called when we start the thread""" """This gets called when we start the thread"""