Make it keeping reconnecting forever.
authorBernard Blackham <dagobah@ucc.asn.au>
Sun, 1 Aug 2004 04:55:29 +0000 (04:55 +0000)
committerBernard Blackham <dagobah@ucc.asn.au>
Sun, 1 Aug 2004 04:55:29 +0000 (04:55 +0000)
sql-edition/servers/VendServer.py
sql-edition/servers/VendingMachine.py

index cea3cfa..8017d3a 100755 (executable)
@@ -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:
index 9fe5245..89dd09e 100644 (file)
@@ -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:]

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