The program closes automatically after 2h python

0

I have a program in python that allows me to read and store values every 10 seconds (to collect data). The program is simple and works well but the problem is that it only works 2h and 24 minutes. Then without knowing why it closes and you have to rerun it. Any suggestions?

''' 
    Use supervisor library to Read PLC each 10 seconds and insert values to mysql DB
'''
import time
import supervisor

#sample time (seconds)
sampleTime=10 

#connect to plc and mysql
[opc,cursor]=supervisor.connect() 

print "+------------------------+"
print "| Recording PLC to MySQL | Sample Time: %s seconds" % sampleTime
print "+------------------------+"

while True:
    opcState = opc.ping() #check connection
    if not(opcState): print ' [!] ERROR not connected to PLC. Exiting...'; break;

    print " === New Reading: %s" % (time.asctime())     #display time 

    #iterate device types that we want to store
    deviceTypes=['Sensor','Alarm','Equipment','Setpoint']
    supervisor.readAndStore(cursor,opc,deviceTypes)

    print " [+] Sleeping %s seconds...\n\n" % (sampleTime)
    time.sleep(sampleTime)
    
asked by Albert G 15.05.2017 в 18:31
source

0 answers