From: Bernard Blackham Date: Sun, 1 Aug 2004 04:55:29 +0000 (+0000) Subject: Make it keeping reconnecting forever. X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=7b35ffb56a0b07005e1e6a1642c9104f42059f39;p=zanchey%2Fdispense2.git Make it keeping reconnecting forever. --- 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:]