Procházet zdrojové kódy

Queue cleaning on state change implemented

mod_update
Dirk Alders před 4 roky
rodič
revize
4abc0d9fa3
3 změnil soubory, kde provedl 12 přidání a 1 odebrání
  1. 5
    0
      config_example/config.py
  2. 1
    1
      leyk.py
  3. 6
    0
      piface_function.py

+ 5
- 0
config_example/config.py Zobrazit soubor

@@ -12,6 +12,11 @@ secret = b'give_a_secret_string_here'
12 12
 server_ip = '127.0.0.1'
13 13
 server_port = 10001
14 14
 
15
+LOG_TARGET_STDOUT = 'stdout'
16
+LOG_TARGET_FILE = 'logfile'
17
+LOG_TARGET = LOG_TARGET_STDOUT
18
+
19
+
15 20
 SHORT_FMT = "%(asctime)s: %(levelname)-7s - %(message)s"
16 21
 """ A short formatter including the most important information"""
17 22
 LONG_FMT = """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 1
- 1
leyk.py Zobrazit soubor

@@ -10,7 +10,7 @@ import time
10 10
 
11 11
 
12 12
 if __name__ == '__main__':
13
-    report.appLoggingConfigure(os.path.dirname(__file__), 'logfile', config.loggers)
13
+    report.appLoggingConfigure(os.path.dirname(__file__), config.LOG_TARGET, config.loggers)
14 14
     s = tcp_socket.tcp_server_stp(config.server_ip, port=config.server_port)
15 15
     prot = protocol.my_server_protocol(s, secret=config.secret)
16 16
     while True:

+ 6
- 0
piface_function.py Zobrazit soubor

@@ -290,6 +290,7 @@ class leyk(object):
290 290
         self._task_1s = task.periodic(1, self.task_1s)
291 291
         self._task_1s.run()
292 292
         self.sm_mode.register_state_change_callback(self.sm_mode.STATE_MANUAL, None, self._queue.clean_queue)
293
+        self.sm_day_state.register_state_change_callback(None, None, self.clean_queue)
293 294
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SLEEP, None, self.sm_day_state.report_sunset_sunrise)
294 295
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SLEEP, None, self.fill_sleep_queue)
295 296
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SUNRISE, None, self.sm_day_state.report_sunset_sunrise)
@@ -413,6 +414,11 @@ class leyk(object):
413 414
                 time.sleep(0.2)
414 415
                 cnt += 1
415 416
 
417
+    def clean_queue(self):
418
+        if self._queue.qsize() > 0:
419
+            logger.info('Cleaning up remaining %d elements from queue', self._queue.qsize())
420
+            self._queue.clean_queue()
421
+
416 422
     def fill_wake_queue(self):
417 423
         no_delay = self.sm_day_state.previous_state_was(self.sm_day_state.STATE_IDLE)
418 424
         # WAKE

Načítá se…
Zrušit
Uložit