From 13319e2606d48167338675bb4128aad63bf95934 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Sun, 20 Feb 2022 20:00:30 +0100 Subject: [PATCH] add timeout to unblock idle state --- fishy/engine/semifisher/fishing_mode.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fishy/engine/semifisher/fishing_mode.py b/fishy/engine/semifisher/fishing_mode.py index ec2c505..81befd5 100644 --- a/fishy/engine/semifisher/fishing_mode.py +++ b/fishy/engine/semifisher/fishing_mode.py @@ -1,7 +1,8 @@ from enum import Enum +from time import time, sleep subscribers = [] - +checkpoint = 0 class State(Enum): IDLE = 0 @@ -32,9 +33,17 @@ def loop(state_num: int): Executed in the start of the main loop in fishy.py Changes modes, calls mode events (callbacks) when mode is changed """ + global checkpoint FishingMode.CurrentMode = State(state_num) if FishingMode.CurrentMode != FishingMode.PrevMode: + checkpoint = time() _notify(FishingMode.CurrentMode) + elif FishingMode.CurrentMode == State.LOOKING: + if time() - checkpoint > 5: + _notify(FishingMode.CurrentMode) + checkpoint = time() + else: + sleep(0.5) FishingMode.PrevMode = FishingMode.CurrentMode