diff --git a/src/py/flwr/simulation/run_simulation.py b/src/py/flwr/simulation/run_simulation.py index 38a6ee7d6c1..be6410dcbd6 100644 --- a/src/py/flwr/simulation/run_simulation.py +++ b/src/py/flwr/simulation/run_simulation.py @@ -216,6 +216,7 @@ def run_simulation_from_cli() -> None: app_dir=app_dir, run=run, enable_tf_gpu_growth=args.enable_tf_gpu_growth, + delay_start=args.delay_start, verbose_logging=args.verbose, server_app_run_config=fused_config, is_app=is_app, @@ -309,7 +310,6 @@ def run_serverapp_th( f_stop: threading.Event, has_exception: threading.Event, enable_tf_gpu_growth: bool, - delay_launch: int = 3, ) -> threading.Thread: """Run SeverApp in a thread.""" @@ -365,7 +365,6 @@ def server_th_with_start_checks( server_app, ), ) - sleep(delay_launch) serverapp_th.start() return serverapp_th @@ -380,6 +379,7 @@ def _main_loop( enable_tf_gpu_growth: bool, run: Run, exit_event: EventType, + delay_start: int, flwr_dir: Optional[str] = None, client_app: Optional[ClientApp] = None, client_app_attr: Optional[str] = None, @@ -419,6 +419,9 @@ def _main_loop( enable_tf_gpu_growth=enable_tf_gpu_growth, ) + # Buffer time so the `ServerApp` in separate thread is ready + log(DEBUG, "Buffer time delay: %ds", delay_start) + sleep(delay_start) # Start Simulation Engine vce.start_vce( num_supernodes=num_supernodes, @@ -467,6 +470,7 @@ def _run_simulation( flwr_dir: Optional[str] = None, run: Optional[Run] = None, enable_tf_gpu_growth: bool = False, + delay_start: int = 5, verbose_logging: bool = False, is_app: bool = False, ) -> None: @@ -523,6 +527,7 @@ def _run_simulation( enable_tf_gpu_growth, run, exit_event, + delay_start, flwr_dir, client_app, client_app_attr, @@ -610,6 +615,13 @@ def _parse_args_run_simulation() -> argparse.ArgumentParser: "Read more about how `tf.config.experimental.set_memory_growth()` works in " "the TensorFlow documentation: https://www.tensorflow.org/api/stable.", ) + parser.add_argument( + "--delay-start", + type=int, + default=3, + help="Buffer time (in seconds) to delay the start the simulation engine after " + "the `ServerApp`, which runs in a separate thread, has been launched.", + ) parser.add_argument( "--verbose", action="store_true",