* DoorClient.py; cleaned up and has an alarm timeout in case of
authorGrahame Bowland <[email protected]>
Thu, 23 Dec 2004 16:02:02 +0000 (16:02 +0000)
committerGrahame Bowland <[email protected]>
Thu, 23 Dec 2004 16:02:02 +0000 (16:02 +0000)
 getting stuck

sql-edition/servers/DoorClient.py

index 56a4814..d46cebe 100755 (executable)
@@ -2,6 +2,7 @@
 
 from LATClient import LATClient
 from select import select
+import signal
 import sys
 
 def check_door_service(service, test_string="got wombles?"):
@@ -17,7 +18,13 @@ def check_door_service(service, test_string="got wombles?"):
        return "closed"
 
 if __name__ == '__main__':
-       result_codes = { 'open' : 0, 'closed' : 1, 'error' : 2 }
-       result = check_door_service(sys.argv[1])
-       print result
-       sys.exit(result_codes[result])
+       result_codes = { 'open' : 0, 'closed' : 1, 'error' : 2, 'invalid args' : 3}
+       def return_result(result):
+               print result
+               sys.exit(result_codes[result])
+       def timeout(signum, frame):
+               return_result("error")
+       if len(sys.argv) <> 2: return_result('invalid args')
+       signal.signal(signal.SIGALRM, timeout)
+       signal.alarm(15)
+       return_result(check_door_service(sys.argv[1]))

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