Skip to content

Instantly share code, notes, and snippets.

@jmkacz
Created May 29, 2012 15:25
Show Gist options
  • Save jmkacz/2829045 to your computer and use it in GitHub Desktop.
Save jmkacz/2829045 to your computer and use it in GitHub Desktop.
my usage of TProcessPoolServer
import signal
def set_alarm(server):
def clean_shutdown(signum, frame):
for worker in server.workers:
logging.error("Terminating worker: {0}".format(worker))
worker.terminate()
logging.error("Requesting server to stop()")
try:
server.stop()
except (KeyboardInterrupt, SystemExit):
pass
except Exception as err:
logging.exception(err)
def logme(s, *args, **kwargs):
logging.error(">>> {0} <<<".format(s))
clean_shutdown(*args, **kwargs)
signal.signal(signal.SIGALRM, clean_shutdown)
signal.signal(signal.SIGHUP, clean_shutdown)
signal.signal(signal.SIGINT, clean_shutdown)
signal.signal(signal.SIGTERM, lambda x, y: logme("SIGTERM", x, y))
server = TProcessPoolServer(processor, transport, tfactory, pfactory)
set_alarm(server)
server.serve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment