Commit 685061ad1997e916f75ef7a6ebf7283116b19792
1 parent
9fb55909
Exists in
dev
ajout temporisation 1s par defaut ; use self.set_delay() pour changer
Showing
1 changed file
with
16 additions
and
12 deletions
Show diff stats
src/core/pyros_django/agent/Agent.py
... | ... | @@ -320,10 +320,11 @@ class Agent: |
320 | 320 | WITH_SIMULATOR = False |
321 | 321 | #TEST_MODE = False |
322 | 322 | |
323 | - # Wait a random number of seconds before each loop ? | |
324 | - # - NO by default | |
325 | - WITH_RANDOM_WAIT = False | |
326 | - # - YES if TEST mode (in __init__) | |
323 | + # Wait a fixed number of seconds before each loop ? | |
324 | + #WITH_RANDOM_WAIT = False | |
325 | + # 1 sec by default | |
326 | + _DELAY_NB_SEC = 1 | |
327 | + # - YES if TEST mode (in init()) | |
327 | 328 | |
328 | 329 | # Default LOG level is INFO |
329 | 330 | #PYROS_DEFAULT_GLOBAL_LOG_LEVEL = LogPyros.LOG_LEVEL_INFO # INFO |
... | ... | @@ -1099,14 +1100,14 @@ class Agent: |
1099 | 1100 | self.DO_MAIN_LOOP = False |
1100 | 1101 | return |
1101 | 1102 | |
1102 | - # (if self.WITH_RANDOM_WAIT) Wait a random number of sec before starting iteration | |
1103 | - # (to let another agent having the chance to send a command before me) | |
1104 | - if self.WITH_RANDOM_WAIT : | |
1105 | - random_waiting_sec = random.randint(0,5) | |
1106 | - random_waiting_sec = 1 | |
1107 | - log.info(f"Waiting {random_waiting_sec} sec (random) before starting new iteration...") | |
1103 | + # Temporizing (delay) : Wait a random number of sec before starting iteration | |
1104 | + # (to avoid to busy to much the processor) | |
1105 | + # (also to let another agent having the chance to send a me command) | |
1106 | + if self._DELAY_NB_SEC : | |
1107 | + #random_waiting_sec = random.randint(0,5) | |
1108 | + log.info(f"Waiting {self._DELAY_NB_SEC} sec (random) before starting new iteration...") | |
1108 | 1109 | #time.sleep(random_waiting_sec) |
1109 | - self.waitfor(random_waiting_sec) | |
1110 | + self.waitfor(self._DELAY_NB_SEC) | |
1110 | 1111 | |
1111 | 1112 | # (Test only) |
1112 | 1113 | # EXIT because max duration reached ? |
... | ... | @@ -1461,6 +1462,9 @@ class Agent: |
1461 | 1462 | # return True |
1462 | 1463 | |
1463 | 1464 | |
1465 | + def set_delay(self, delay_nb_sec:int): | |
1466 | + self._DELAY_NB_SEC = delay_nb_sec | |
1467 | + | |
1464 | 1468 | """ |
1465 | 1469 | ======================================================================================= |
1466 | 1470 | Generic methods that may be specialized (overriden) by subclasses (except if private) |
... | ... | @@ -1472,7 +1476,7 @@ class Agent: |
1472 | 1476 | #log.debug("*** Initializing... ***") |
1473 | 1477 | log.info("*** INITIALIZING... ***") |
1474 | 1478 | self._set_status(self.STATUS_INIT) |
1475 | - if self.TEST_MODE: self.WITH_RANDOM_WAIT = True | |
1479 | + if self.TEST_MODE: self.set_delay(2) | |
1476 | 1480 | |
1477 | 1481 | |
1478 | 1482 | def _reload_config_if_changed(self): | ... | ... |