ServerApp

class ServerApp(server: Server | None = None, config: ServerConfig | None = None, strategy: Strategy | None = None, client_manager: ClientManager | None = None, server_fn: Callable[[Context], ServerAppComponents] | None = None)[소스]

기반 클래스: object

Flower 서버.

예제

Use the ServerApp with an existing Strategy:

def server_fn(context: Context):
    server_config = ServerConfig(num_rounds=3)
    strategy = FedAvg()
    return ServerAppComponents(
        strategy=strategy,
        server_config=server_config,
    )

app = ServerApp(server_fn=server_fn)

Use the ServerApp with a custom main function:

app = ServerApp()

@app.main()
def main(grid: Grid, context: Context) -> None:
   print("ServerApp running")

메소드

lifespan()

Return a decorator that registers the lifespan fn with the server app.

main()

Return a decorator that registers the main fn with the server app.

lifespan() Callable[[Callable[[Context], Iterator[None]]], Callable[[Context], Iterator[None]]][소스]

Return a decorator that registers the lifespan fn with the server app.

The decorated function should accept a Context object and use yield to define enter and exit behavior.

예제

app = ServerApp()

@app.lifespan()
def lifespan(context: Context) -> None:
    # Perform initialization tasks before the app starts
    print("Initializing ServerApp")

    yield  # ServerApp is running

    # Perform cleanup tasks after the app stops
    print("Cleaning up ServerApp")
main() Callable[[Callable[[Grid, Context], None]], Callable[[Grid, Context], None]][소스]

Return a decorator that registers the main fn with the server app.

예제

app = ServerApp()

@app.main()
def main(grid: Grid, context: Context) -> None:
    print("ServerApp running")