From: Grahame Bowland Date: Thu, 23 Dec 2004 16:02:02 +0000 (+0000) Subject: * DoorClient.py; cleaned up and has an alarm timeout in case of X-Git-Tag: IMPORT-FROM-UCCCVS~44 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=606375934014125211e3a23ddcd51d18a05f953a;p=uccvend-vendserver.git * DoorClient.py; cleaned up and has an alarm timeout in case of getting stuck --- diff --git a/sql-edition/servers/DoorClient.py b/sql-edition/servers/DoorClient.py index 56a4814..d46cebe 100755 --- a/sql-edition/servers/DoorClient.py +++ b/sql-edition/servers/DoorClient.py @@ -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]))