From: Cameron Patrick Date: Sun, 1 Aug 2004 06:20:50 +0000 (+0000) Subject: add signal handling code, misc cleanups X-Git-Tag: IMPORT-FROM-UCCCVS~92 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=af695fbe4e5a26687122cc706ee7ebfadf95a792;p=uccvend-vendserver.git add signal handling code, misc cleanups --- diff --git a/sql-edition/servers/LATClient.py b/sql-edition/servers/LATClient.py index fd5cf23..7c21d0d 100644 --- a/sql-edition/servers/LATClient.py +++ b/sql-edition/servers/LATClient.py @@ -88,13 +88,12 @@ class LATClient: def read_reply(self): head = self.sock.recv(3) if len(head) != 3: - sys.stderr.write('Error: Short LAT packet\n') - return None + raise LATClientException('Short LAT packet') cmd = head[0] length = ord(head[1])*256 + ord(head[2]) msg = self.sock.recv(length) if cmd == LATCP_CMD_ERRORMSG: - sys.stderr.write('Error: Received LAT error: %s\n'%msg) + raise LATClientException('Received LAT error: %s'%msg) return (cmd, msg) def get_fh(self): diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index d912256..8d1f432 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -4,7 +4,8 @@ USE_DB = 0 import ConfigParser -import sys, os, string, re, pwd +import sys, os, string, re, pwd, signal +from traceback import print_tb if USE_DB: import pg from time import time, sleep from popen2 import popen2 @@ -447,13 +448,17 @@ def do_vend_server(): print print "Connection died, trying again..." - if __name__ == '__main__': + def do_nothing(signum, stack): pass + def stop_server(signum, stack): raise KeyboardInterrupt + signal.signal(signal.SIGHUP, do_nothing) + signal.signal(signal.SIGTERM, stop_server) + signal.signal(signal.SIGINT, stop_server) while True: try: do_vend_server() except KeyboardInterrupt: - print "Killed by SIGINT." + print "Killed by signal." break except: (exc_type, exc_value, exc_traceback) = sys.exc_info()