@@ -73,14 +73,14 @@ def __init__(self, version):
7373 N_ ('wattage' ) : 'W' ,
7474 }
7575
76- self .__engine = {'exit' : threading .Event (), 'thread' : None , 'logtail' : None , 'too_late' : 0 }
76+ self .__engine = {'exit' : threading .Event (), 'thread' : None , 'logtail' : None , 'too_late' : 0 , 'systemd' : sdnotify . SystemdNotifier () }
7777
7878 self .version = version
7979 self .latest_version = None
8080 init_db (self .version )
8181
82- n = sdnotify . SystemdNotifier ()
83- n .notify ('READY=1' )
82+ # Send message that startup is ready..... else the startup will wait until done.... can take more then 1 minute
83+ self . __engine [ 'systemd' ] .notify ('READY=1' )
8484
8585 self .running = True
8686
@@ -944,8 +944,7 @@ def __engine_loop(self):
944944 prev_delay = 0
945945
946946 while not self .__engine ['exit' ].is_set ():
947- n = sdnotify .SystemdNotifier ()
948- n .notify ('WATCHDOG=1' )
947+ self .__engine ['systemd' ].notify ('WATCHDOG=1' )
949948 print (f'[{ datetime .datetime .now ()} ] Start updating ....' )
950949
951950 logger .info (f'Starting a new update round with { len (self .sensors )} sensors, { len (self .relays )} relays, { len (self .buttons )} buttons and { len (self .webcams )} webcams.' )
@@ -1254,31 +1253,12 @@ def stop(self):
12541253 logger .info (f'Stopping TerrariumPI { self .version } ...' )
12551254
12561255 self .running = False
1257-
1258- # Stop engine processing first....
1259- # print('Trigger exit event')
1260- # print(self.__engine['exit'])
1261- # print(dir(self.__engine['exit']))
1262-
12631256 self .__engine ['exit' ].set ()
1264- # print('Exit event done')
12651257
1266- # # Wait till the engine is done, when it was updating the sensors
1267- # print('Stop logtail process')
1258+ # Wait till the engine is done, when it was updating the sensors
12681259 self .__logtail_process .terminate ()
1269- # print('Logtail process is done')
1270-
1271- # print('Wait on the engine to stop...')
1272- # print(self.__engine['thread'])
1273- # print(f' Thread alive: {self.__engine["thread"].is_alive()}')
1274- # print(f' Thread daemon: {self.__engine["thread"].isDaemon()}')
1275- # print(dir(self.__engine['thread']))
1276-
12771260 self .__engine ['thread' ].join ()
1278- # print('Engine stopped...')
1279- # print('Wait on logtail to stop....')
12801261 self .__engine ['logtail' ].join ()
1281- # print('Logtail thread is stopped')
12821262
12831263 for enclosure in self .enclosures :
12841264 self .enclosures [enclosure ].stop ()
@@ -1301,7 +1281,6 @@ def stop(self):
13011281 logger .info (f'Stopped { self .webcams [webcam ]} ' )
13021282
13031283 self .notification .stop ()
1304- # print('Totally stopped TerrariumPI')
13051284
13061285 def replace_hardware_calender_event (self ,switch_id ,device ,reminder_amount ,reminder_period ):
13071286 # Two events:
0 commit comments