Skip to content

Commit

Permalink
use time.sleep as default
Browse files Browse the repository at this point in the history
  • Loading branch information
panh99 committed Mar 31, 2024
1 parent 8d8cbb5 commit 806a775
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/py/flwr/common/retry_invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def __init__(
self.on_giveup = on_giveup
self.jitter = jitter
self.should_giveup = should_giveup
if wait_function is None:
wait_function = time.sleep
self.wait_function = wait_function

# pylint: disable-next=too-many-locals
Expand Down Expand Up @@ -241,12 +243,12 @@ def try_call_event_handler(

try_cnt = 0
wait_generator = self.wait_gen_factory()
start = time.time()
start = time.monotonic()
ref_state: List[Optional[RetryState]] = [None]

while True:
try_cnt += 1
elapsed_time = time.time() - start
elapsed_time = time.monotonic() - start
state = RetryState(
target=target,
args=args,
Expand Down
4 changes: 2 additions & 2 deletions src/py/flwr/common/retry_invoker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def failing_function() -> None:

@pytest.fixture(name="mock_time")
def fixture_mock_time() -> Generator[MagicMock, None, None]:
"""Mock time.time for controlled testing."""
with patch("time.time") as mock_time:
"""Mock time.monotonic for controlled testing."""
with patch("time.monotonic") as mock_time:
yield mock_time


Expand Down

0 comments on commit 806a775

Please sign in to comment.