mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-21 13:33:47 +08:00
Refactor sunnylinkd.main exit conditions
The checks for the sunnylink_enabled flag have been restructured to eliminate unnecessary loop iterations. The check has been moved out of the loop to do the evaluation only once, when exiting the loop. This significantly increases the efficiency of the code.
This commit is contained in:
@@ -202,13 +202,8 @@ def main(exit_event: threading.Event = None):
|
||||
ws_uri = SUNNYLINK_ATHENA_HOST
|
||||
conn_start = None
|
||||
conn_retries = 0
|
||||
while exit_event is None or not exit_event.is_set():
|
||||
while exit_event is None or not exit_event.is_set() and is_sunnylink_enabled:
|
||||
try:
|
||||
if not is_sunnylink_enabled:
|
||||
cloudlog.debug("Exiting sunnylinkd.main as SunnylinkEnabled is False but will retry in 60 seconds")
|
||||
time.sleep(60)
|
||||
break
|
||||
|
||||
if conn_start is None:
|
||||
conn_start = time.monotonic()
|
||||
|
||||
@@ -238,6 +233,10 @@ def main(exit_event: threading.Event = None):
|
||||
|
||||
time.sleep(backoff(conn_retries))
|
||||
|
||||
if not is_sunnylink_enabled:
|
||||
cloudlog.debug("Reached end of sunnylinkd.main while SunnylinkEnabled is False so will wait for 60 seconds before exiting")
|
||||
time.sleep(60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user