updates pydase.Server docstring

This commit is contained in:
Mose Müller 2024-04-16 10:19:37 +02:00
parent 8911b860d7
commit 6977b795e5

View File

@ -78,71 +78,67 @@ class Server:
Args: Args:
service: DataService service: DataService
The DataService instance that this server will manage. The DataService instance that this server will manage.
host: str host: str
The host address for the server. Default is '0.0.0.0', which means all The host address for the server. Default is '0.0.0.0', which means all
available network interfaces. available network interfaces.
rpc_port: int
The port number for the RPC server. Default is
`pydase.config.ServiceConfig().rpc_port`.
web_port: int web_port: int
The port number for the web server. Default is The port number for the web server. Default is
`pydase.config.ServiceConfig().web_port`. `pydase.config.ServiceConfig().web_port`.
enable_rpc: bool
Whether to enable the RPC server. Default is True.
enable_web: bool enable_web: bool
Whether to enable the web server. Default is True. Whether to enable the web server. Default is True.
filename: str | Path | None filename: str | Path | None
Filename of the file managing the service state persistence. Defaults to None. Filename of the file managing the service state persistence.
use_forking_server: bool Defaults to None.
Whether to use ForkingServer for multiprocessing. Default is False.
additional_servers : list[AdditionalServer] additional_servers : list[AdditionalServer]
A list of additional servers to run alongside the main server. Each entry in A list of additional servers to run alongside the main server. Each entry in
the list should be a dictionary with the following structure: the list should be a dictionary with the following structure:
- server: A class that adheres to the AdditionalServerProtocol. This class - server: A class that adheres to the AdditionalServerProtocol. This
should have an `__init__` method that accepts the DataService instance, class should have an `__init__` method that accepts the DataService
port, host, and optional keyword arguments, and a `serve` method that is instance, port, host, and optional keyword arguments, and a `serve`
a coroutine responsible for starting the server. method that is a coroutine responsible for starting the server.
- port: The port on which the additional server will be running. - port: The port on which the additional server will be running.
- kwargs: A dictionary containing additional keyword arguments that will be - kwargs: A dictionary containing additional keyword arguments that will
passed to the server's `__init__` method. be passed to the server's `__init__` method.
Here's an example of how you might define an additional server: Here's an example of how you might define an additional server:
```python
class MyCustomServer:
def __init__(
self,
data_service_observer: DataServiceObserver,
host: str,
port: int,
**kwargs: Any,
) -> None:
self.observer = data_service_observer
self.state_manager = self.observer.state_manager
self.service = self.state_manager.service
self.port = port
self.host = host
# handle any additional arguments...
>>> class MyCustomServer: async def serve(self):
... def __init__( # code to start the server...
... self, ```
... data_service_observer: DataServiceObserver,
... host: str,
... port: int,
... **kwargs: Any,
... ) -> None:
... self.observer = data_service_observer
... self.state_manager = self.observer.state_manager
... self.service = self.state_manager.service
... self.port = port
... self.host = host
... # handle any additional arguments...
...
... async def serve(self):
... # code to start the server...
And here's how you might add it to the `additional_servers` list when creating And here's how you might add it to the `additional_servers` list when
a `Server` instance: creating a `Server` instance:
>>> server = Server(
... service=my_data_service,
... additional_servers=[
... {
... "server": MyCustomServer,
... "port": 12345,
... "kwargs": {"some_arg": "some_value"}
... }
... ],
... )
... server.run()
```python
server = Server(
service=my_data_service,
additional_servers=[
{
"server": MyCustomServer,
"port": 12345,
"kwargs": {"some_arg": "some_value"}
}
],
)
server.run()
```
**kwargs: Any **kwargs: Any
Additional keyword arguments. Additional keyword arguments.
""" """