Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clientapp exit bool test #3522

Merged
merged 3 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def _load_client_app() -> ClientApp:
run_tracker = _RunTracker()

def _on_sucess(retry_state: RetryState) -> None:
run_tracker.connection = True
if retry_state.tries > 1:
log(
INFO,
Expand All @@ -280,7 +279,6 @@ def _on_sucess(retry_state: RetryState) -> None:
run_tracker.create_node()

def _on_backoff(retry_state: RetryState) -> None:
run_tracker.connection = False
if retry_state.tries == 1:
log(WARN, "Connection attempt failed, retrying...")
else:
Expand Down Expand Up @@ -311,7 +309,7 @@ def _on_backoff(retry_state: RetryState) -> None:

node_state = NodeState()

while True:
while not run_tracker.interrupt:
sleep_duration: int = 0
with connection(
address,
Expand All @@ -330,7 +328,7 @@ def _on_backoff(retry_state: RetryState) -> None:
create_node() # pylint: disable=not-callable

run_tracker.register_signal_handler()
while True:
while not run_tracker.interrupt:
try:
# Receive
message = receive()
Expand Down Expand Up @@ -404,7 +402,10 @@ def _on_backoff(retry_state: RetryState) -> None:
e_code = ErrorCode.LOAD_CLIENT_APP_EXCEPTION
exc_entity = "SuperNode"

log(ERROR, "%s raised an exception", exc_entity, exc_info=ex)
if not run_tracker.interrupt:
log(
ERROR, "%s raised an exception", exc_entity, exc_info=ex
)

# Create error message
reply_message = message.create_error_reply(
Expand All @@ -425,10 +426,6 @@ def _on_backoff(retry_state: RetryState) -> None:
sleep_duration = 0
break

# Unregister node
if delete_node is not None and run_tracker.connection:
delete_node() # pylint: disable=not-callable

if sleep_duration == 0:
log(INFO, "Disconnect and shut down")
del run_tracker
Expand Down Expand Up @@ -606,14 +603,15 @@ def _init_connection(transport: Optional[str], server_address: str) -> Tuple[

@dataclass
class _RunTracker:
connection: bool = True
create_node: Optional[Callable[[], None]] = None
interrupt: bool = False

def register_signal_handler(self) -> None:
"""Register handlers for exit signals."""

def signal_handler(sig, frame): # type: ignore
# pylint: disable=unused-argument
self.interrupt = True
raise StopIteration from None

signal.signal(signal.SIGINT, signal_handler)
Expand Down