From f2651fa924fc99c0304e187cb1adc1ed8b638214 Mon Sep 17 00:00:00 2001 From: Bernard Blackham Date: Sun, 1 Aug 2004 04:55:29 +0000 Subject: [PATCH] Make it keeping reconnecting forever. --- sql-edition/servers/VendServer.py | 13 ++++++++++++- sql-edition/servers/VendingMachine.py | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index cea3cfa..8017d3a 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -8,10 +8,12 @@ if USE_DB: import pg from time import time, sleep from popen2 import popen2 from LATClient import LATClient -from VendingMachine import VendingMachine +from VendingMachine import VendingMachine, VendingException from HorizScroll import HorizScroll from random import random, seed from Idler import TrainIdler,GrayIdler +import socket +from traceback import print_tb GREETING = 'UCC SNACKS' PIN_LENGTH = 4 @@ -406,7 +408,16 @@ if __name__ == '__main__': PrivPassword = cp.get('DecServer', 'PrivPassword') while True: + try: rfh, wfh = connect_to_vend(options, DBServer, DBName, DBUser, DBPassword, ServiceName, ServicePassword, ServerName, ConnectPassword, PrivPassword) + except Exception: + (exc_type, exc_value, exc_traceback) = sys.exc_info() + print "Connection error ("+str(exc_type)+"):" + print_tb(exc_traceback) + del exc_traceback + print "Trying again in 5 seconds." + sleep(5) + continue try: run_forever(rfh, wfh) except VendingException: diff --git a/sql-edition/servers/VendingMachine.py b/sql-edition/servers/VendingMachine.py index 9fe5245..89dd09e 100644 --- a/sql-edition/servers/VendingMachine.py +++ b/sql-edition/servers/VendingMachine.py @@ -62,7 +62,8 @@ class VendingMachine: s = '' while s == '': s = self.rfh.readline() - if s == '': return None + if s == '': + raise VendingException('Input socket has closed!') s = s.strip('\r\n') code = s[0:3] text = s[4:] -- 2.20.1