Browse Source

Queue cleaning on state change implemented

mod_update
Dirk Alders 4 years ago
parent
commit
4abc0d9fa3
3 changed files with 12 additions and 1 deletions
  1. 5
    0
      config_example/config.py
  2. 1
    1
      leyk.py
  3. 6
    0
      piface_function.py

+ 5
- 0
config_example/config.py View File

12
 server_ip = '127.0.0.1'
12
 server_ip = '127.0.0.1'
13
 server_port = 10001
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
 SHORT_FMT = "%(asctime)s: %(levelname)-7s - %(message)s"
20
 SHORT_FMT = "%(asctime)s: %(levelname)-7s - %(message)s"
16
 """ A short formatter including the most important information"""
21
 """ A short formatter including the most important information"""
17
 LONG_FMT = """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
 LONG_FMT = """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 1
- 1
leyk.py View File

10
 
10
 
11
 
11
 
12
 if __name__ == '__main__':
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
     s = tcp_socket.tcp_server_stp(config.server_ip, port=config.server_port)
14
     s = tcp_socket.tcp_server_stp(config.server_ip, port=config.server_port)
15
     prot = protocol.my_server_protocol(s, secret=config.secret)
15
     prot = protocol.my_server_protocol(s, secret=config.secret)
16
     while True:
16
     while True:

+ 6
- 0
piface_function.py View File

290
         self._task_1s = task.periodic(1, self.task_1s)
290
         self._task_1s = task.periodic(1, self.task_1s)
291
         self._task_1s.run()
291
         self._task_1s.run()
292
         self.sm_mode.register_state_change_callback(self.sm_mode.STATE_MANUAL, None, self._queue.clean_queue)
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
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SLEEP, None, self.sm_day_state.report_sunset_sunrise)
294
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SLEEP, None, self.sm_day_state.report_sunset_sunrise)
294
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SLEEP, None, self.fill_sleep_queue)
295
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SLEEP, None, self.fill_sleep_queue)
295
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SUNRISE, None, self.sm_day_state.report_sunset_sunrise)
296
         self.sm_day_state.register_state_change_callback(self.sm_day_state.STATE_SUNRISE, None, self.sm_day_state.report_sunset_sunrise)
413
                 time.sleep(0.2)
414
                 time.sleep(0.2)
414
                 cnt += 1
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
     def fill_wake_queue(self):
422
     def fill_wake_queue(self):
417
         no_delay = self.sm_day_state.previous_state_was(self.sm_day_state.STATE_IDLE)
423
         no_delay = self.sm_day_state.previous_state_was(self.sm_day_state.STATE_IDLE)
418
         # WAKE
424
         # WAKE

Loading…
Cancel
Save