Move server control code to the top

This commit is contained in:
Anders Ingemann 2015-01-25 19:29:49 +01:00
parent 4582ea1498
commit 51e9e29b24

View file

@ -61,6 +61,32 @@ class Server(object):
daemon.requestLoop(loopCondition=lambda: not self.stop_serving) daemon.requestLoop(loopCondition=lambda: not self.stop_serving)
@Pyro4.expose
def set_callback_server(self, server):
log.debug('Forwarding logs to the callback server')
self.log_forwarder.set_server(server)
@Pyro4.expose
def ping(self):
if hasattr(self, 'connection_timeout'):
self.connection_timeout.cancel()
del self.connection_timeout
return 'pong'
@Pyro4.expose
def stop(self):
if hasattr(self, 'bootstrap_process'):
log.warn('Sending SIGINT to bootstrapping process')
import os
import signal
os.killpg(self.bootstrap_process.pid, signal.SIGINT)
self.bootstrap_process.join()
# We can't send a SIGINT to the server,
# for some reason the Pyro4 shutdowns are rather unclean,
# throwing exceptions and such.
self.stop_serving = True
@Pyro4.expose @Pyro4.expose
def run(self, manifest, debug=False, dry_run=False): def run(self, manifest, debug=False, dry_run=False):
@ -102,26 +128,3 @@ class Server(object):
if isinstance(result, Exception): if isinstance(result, Exception):
raise result raise result
return result return result
@Pyro4.expose
def set_callback_server(self, server):
log.debug('Forwarding logs to the callback server')
self.log_forwarder.set_server(server)
@Pyro4.expose
def ping(self):
return 'pong'
@Pyro4.expose
def stop(self):
if hasattr(self, 'bootstrap_process'):
log.warn('Sending SIGINT to bootstrapping process')
import os
import signal
os.killpg(self.bootstrap_process.pid, signal.SIGINT)
self.bootstrap_process.join()
# We can't send a SIGINT to the server,
# for some reason the Pyro4 shutdowns are rather unclean,
# throwing exceptions and such.
self.stop_serving = True