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

Expose gRPC parameters in start_client() and start_numpy_client() #1115

Closed
wants to merge 12 commits into from
Closed
8 changes: 8 additions & 0 deletions src/py/flwr/client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def start_client(
client: Client,
grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
root_certificates: Optional[bytes] = None,
wait_for_ready: bool = False,
) -> None:
"""Start a Flower Client which connects to a gRPC server.

Expand All @@ -55,6 +56,8 @@ class `flwr.client.Client`.
The PEM-encoded root certificates as a byte string. If provided, a secure
connection using the certificates will be established to a
SSL-enabled Flower server.
wait_for_ready: bool (default: False). If set to True, the client does not
fail fast, but waits until a connection to the server can be established.

Returns
-------
Expand Down Expand Up @@ -84,6 +87,7 @@ class `flwr.client.Client`.
server_address,
max_message_length=grpc_max_message_length,
root_certificates=root_certificates,
wait_for_ready=wait_for_ready,
) as conn:
receive, send = conn

Expand Down Expand Up @@ -112,6 +116,7 @@ def start_numpy_client(
client: NumPyClient,
grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
root_certificates: Optional[bytes] = None,
wait_for_ready: bool = False,
) -> None:
"""Start a Flower NumPyClient which connects to a gRPC server.

Expand All @@ -133,6 +138,8 @@ class `flwr.client.NumPyClient`.
The PEM-encoded root certificates a byte string. If provided, a secure
connection using the certificates will be established to a
SSL-enabled Flower server.
wait_for_ready: bool (default: False). If set to True, the client does not
fail fast, but waits until a connection to the server can be established.

Returns
-------
Expand Down Expand Up @@ -173,4 +180,5 @@ class `flwr.client.NumPyClient`.
client=flower_client,
grpc_max_message_length=grpc_max_message_length,
root_certificates=root_certificates,
wait_for_ready=wait_for_ready,
)
7 changes: 6 additions & 1 deletion src/py/flwr/client/grpc_client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def grpc_connection(
server_address: str,
max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
root_certificates: Optional[bytes] = None,
wait_for_ready: bool = False,
) -> Iterator[Tuple[Callable[[], ServerMessage], Callable[[ClientMessage], None]]]:
"""Establish an insecure gRPC connection to a gRPC server.

Expand All @@ -64,6 +65,8 @@ def grpc_connection(
The PEM-encoded root certificates as a byte string. If provided, a secure
connection using the certificates will be established to a SSL-enabled
Flower server.
wait_for_ready: bool (default: False). If set to True, the client does not
fail fast, but waits until a connection to the server can be established.

Returns
-------
Expand Down Expand Up @@ -108,7 +111,9 @@ def grpc_connection(
)
stub = FlowerServiceStub(channel)

server_message_iterator: Iterator[ServerMessage] = stub.Join(iter(queue.get, None))
server_message_iterator: Iterator[ServerMessage] = stub.Join(
iter(queue.get, None), wait_for_ready=wait_for_ready
)

receive: Callable[[], ServerMessage] = lambda: next(server_message_iterator)
send: Callable[[ClientMessage], None] = lambda msg: queue.put(msg, block=False)
Expand Down