Server#

Contains the directives necessary to start the DPF server.

ansys.dpf.core.server.has_local_server()#

Check if a local DPF gRPC server has been created.

Returns:

True when a local DPF gRPC server has been created.

Return type:

bool

ansys.dpf.core.server.set_server_configuration(server_config: ansys.dpf.core.server_factory.ServerConfig)#

Sets, for the current python session, the default type of DPF server to use.

Parameters:

server_config (ServerConfig) – Manages the type of server connection to use by default.

Return type:

None

ansys.dpf.core.server.port_in_use(port, host='127.0.0.1')#

Check if a port is in use at the given host.

The port must actually “bind” the address. Just checking to see if a socket can be created is insufficient because it’s possible to run into permission errors like: An attempt was made to access a socket in a way forbidden by its access permissions.

Returns:

True when the port is in use, False when free.

Return type:

bool

ansys.dpf.core.server.shutdown_all_session_servers()#

Shut down all active servers created by this module.

ansys.dpf.core.server.start_local_server(ip='127.0.0.1', port=50054, ansys_path=None, as_global=True, load_operators=True, use_docker_by_default=True, docker_config=<ansys.dpf.core.server_factory.DockerConfig object>, timeout=20.0, config=None, use_pypim_by_default=True, context=None)#

Start a new local DPF server at a given port and IP address.

This method requires Windows and ANSYS 2021 R1 or later. If as_global=True, which is the default) the server is stored globally, replacing the one stored previously. Otherwise, a user must keep a handle on their server.

Parameters:
  • ip (str, optional) – IP address of the remote or local instance to connect to. The default is "LOCALHOST".

  • port (int, optional) – Port to connect to the remote instance on. The default is "DPF_DEFAULT_PORT", which is 50054.

  • ansys_path (str or os.PathLike, optional) – Root path for the Ansys installation directory. For example, "/ansys_inc/v212/". The default is the latest Ansys installation.

  • as_global (bool, optional) – Global variable that stores the IP address and port for the DPF module. All DPF objects created in this Python session will use this IP and port. The default is True.

  • load_operators (bool, optional) – Whether to automatically load the math operators. The default is True.

  • use_docker_by_default (bool, optional) – If the environment variable DPF_DOCKER is set to a docker name and use_docker_by_default is True, the server is ran as a docker (default is True).

  • docker_config (server_factory.DockerConfig, optional) – To start DPF server as a docker, specify the docker configuration options here.

  • timeout (float, optional) – Maximum number of seconds for the initialization attempt. The default is 10. Once the specified number of seconds passes, the connection fails.

  • config (ServerConfig, optional) – Manages the type of server connection to use.

  • use_pypim_by_default (bool, optional) – Whether to use PyPIM functionalities by default when a PyPIM environment is detected. Defaults to True.

  • context (ServerContext, optional) – Defines the settings that will be used to load DPF’s plugins. A DPF xml file can be used to list the plugins and set up variables. Default is server_context.SERVER_CONTEXT.

Returns:

server

Return type:

server.ServerBase

ansys.dpf.core.server.connect_to_server(ip='127.0.0.1', port=50054, as_global=True, timeout=5, config=None, context=None)#

Connect to an existing DPF server.

This method sets the global default channel that is then used for the duration of the DPF session.

Parameters:
  • ip (str) – IP address of the remote or local instance to connect to. The default is "LOCALHOST".

  • port (int) – Port to connect to the remote instance on. The default is "DPF_DEFAULT_PORT", which is 50054.

  • as_global (bool, optional) – Global variable that stores the IP address and port for the DPF module. All DPF objects created in this Python session will use this IP and port. The default is True.

  • timeout (float, optional) – Maximum number of seconds for the initialization attempt. The default is 10. Once the specified number of seconds passes, the connection fails.

  • config (ServerConfig, optional) – Manages the type of server connection to use. Forced to LegacyGrpc on macOS.

  • context (ServerContext, optional) – Defines the settings that will be used to load DPF’s plugins. A DPF xml file can be used to list the plugins and set up variables. Default is server_context.SERVER_CONTEXT.

Examples

>>> from ansys.dpf import core as dpf

Create a server.

>>> #server = dpf.start_local_server(ip = '127.0.0.1')
>>> #port = server.port

Connect to a remote server at a non-default port.

>>> #specified_server = dpf.connect_to_server('127.0.0.1', port, as_global=False)

Connect to the localhost at the default port.

>>> #unspecified_server = dpf.connect_to_server(as_global=False)
ansys.dpf.core.server.get_or_create_server(server: ansys.dpf.core.server_types.BaseServer)#

Returns the given server or if None, creates a new one.

Parameters:

server (BaseServer, None) –

Returns:

server

Return type:

returns the newly created server, or the server given.