[DEBUG] correct the stoping of the application and add a store BDD when stop is requested (ctrl+c)

This commit is contained in:
Edouard DUPIN 2019-12-28 21:51:41 +01:00
parent c3ce0b6d35
commit aff5e71cc5
2 changed files with 28 additions and 3 deletions

View File

@ -150,6 +150,9 @@ if __name__ == "__main__":
debug.info("Start REST application: " + str(app.config['REST_HOST']) + ":" + str(app.config['REST_PORT']))
app.config.REQUEST_MAX_SIZE=10*1024*1024*1024
app.run(host=app.config['REST_HOST'], port=int(app.config['REST_PORT']))
#app.stop()
debug.info("Sync all BDD ... (do not force stop ...)");
data_global_elements.save_all_before_stop();
debug.info("END program");
sys.exit(0)

View File

@ -24,11 +24,33 @@ def add_interface(_name, _interface):
import time, threading
def check_save():
print(time.ctime())
system_stop = False
system_counter = 0
def save_all():
global system_counter
system_counter += 1
if system_counter <= 10:
return
system_counter = 0
for elem in interfaces.keys():
if system_stop == True:
return
interfaces[elem].check_save()
def save_all_before_stop():
global system_stop
system_stop = True
for elem in interfaces.keys():
interfaces[elem].check_save()
threading.Timer(10, check_save).start()
def check_save():
print(time.ctime())
save_all()
if system_stop == True:
return
threading.Timer(1, check_save).start()
check_save()