From: Cameron Patrick Date: Sun, 1 Aug 2004 06:20:50 +0000 (+0000) Subject: add signal handling code, misc cleanups X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b04879b3392af38421b5199dd690282c85cabbc4;p=zanchey%2Fdispense2.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()