add signal handling code, misc cleanups
authorCameron Patrick <[email protected]>
Sun, 1 Aug 2004 06:20:50 +0000 (06:20 +0000)
committerCameron Patrick <[email protected]>
Sun, 1 Aug 2004 06:20:50 +0000 (06:20 +0000)
sql-edition/servers/LATClient.py
sql-edition/servers/VendServer.py

index fd5cf23..7c21d0d 100644 (file)
@@ -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):
index d912256..8d1f432 100755 (executable)
@@ -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()

UCC git Repository :: git.ucc.asn.au