From 606375934014125211e3a23ddcd51d18a05f953a Mon Sep 17 00:00:00 2001 From: Grahame Bowland Date: Thu, 23 Dec 2004 16:02:02 +0000 Subject: [PATCH] * DoorClient.py; cleaned up and has an alarm timeout in case of getting stuck --- sql-edition/servers/DoorClient.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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])) -- 2.20.1