Changeset 88:6f7fe3f9ca24 in xplra for misc


Ignore:
Timestamp:
05/12/13 09:05:51 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The program quits when the connection fails

File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/autosavesit.py

    r84 r88  
    2424    xplane = XPlane()
    2525
    26     while True:
    27         print "Connecting to X-Plane..."
     26    print "Connecting to X-Plane..."
    2827
    29         while not xplane.isConnected:
     28    while not xplane.isConnected:
     29        try:
     30            xplane.connect()
     31        except:
     32            print "Connection failed, sleeping..."
     33            time.sleep(0.5)
     34
     35    print "Connected to X-Plane"
     36
     37    try:
     38        while True:
    3039            try:
    31                 xplane.connect()
    32             except:
    33                 print "Connection failed, sleeping..."
    34                 time.sleep(0.5)
     40                xplane.saveSituation(savePath)
     41                try:
     42                    if os.path.exists(path):
     43                        os.rename(path, oldPath)
     44                    os.rename(newPath, path)
    3545
    36         print "Connected to X-Plane"
    37 
     46                    print "Situation saved at " + time.strftime("%H:%M:%S")
     47                except OSError, e:
     48                    print "I/O error occured: " + str(e)
     49            except ProtocolException, e:
     50                print "Protocol error occured: " + str(e)
     51            time.sleep(interval)
     52    except Exception, e:
     53        print "Connection failed: " + str(e)
    3854        try:
    39             while True:
    40                 try:
    41                     xplane.saveSituation(savePath)
    42                     try:
    43                         if os.path.exists(path):
    44                             os.rename(path, oldPath)
    45                         os.rename(newPath, path)
    46 
    47                         print "Situation saved at " + time.strftime("%H:%M:%S")
    48                     except OSError, e:
    49                         print "I/O error occured: " + str(e)
    50                 except ProtocolException, e:
    51                     print "Protocol error occured: " + str(e)
    52                 time.sleep(interval)
    53         except Exception, e:
    54             print "Connection failed: " + str(e)
    5555            xplane.disconnect()
     56        except:
     57            pass
Note: See TracChangeset for help on using the changeset viewer.