Skip to content

Commit

Permalink
Make throttle start time an worker object attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
hroff-1902 committed Feb 21, 2020
1 parent 04aa74e commit e0800b7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions freqtrade/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(self, args: Dict[str, Any], config: Dict[str, Any] = None) -> None:
self._config = config
self._init(False)

self.last_throttle_start_time: float = None

# Tell systemd that we completed initialization phase
if self._sd_notify:
logger.debug("sd_notify: READY=1")
Expand Down Expand Up @@ -107,10 +109,10 @@ def _throttle(self, func: Callable[..., Any], min_secs: float, *args, **kwargs)
:param min_secs: minimum execution time in seconds
:return: Any
"""
start = time.time()
self.last_throttle_start_time = time.time()
logger.debug("========================================")
result = func(*args, **kwargs)
time_passed = time.time() - start
time_passed = time.time() - self.last_throttle_start_time
sleep_duration = max(min_secs - time_passed, 0.0)
logger.debug(f"Throttling with '{func.__name__}()': sleep for {sleep_duration:.2f} s, "
f"last iteration took {time_passed:.2f} s.")
Expand Down

0 comments on commit e0800b7

Please sign in to comment.