1818
1919from ansys .dpf .core .server_factory import ServerConfig , ServerFactory , CommunicationProtocols
2020from ansys .dpf .core .server_types import DPF_DEFAULT_PORT , LOCALHOST , RUNNING_DOCKER
21+ from ansys .dpf .core import server_context
2122
2223
2324def shutdown_global_server ():
@@ -129,7 +130,8 @@ def start_local_server(
129130 docker_config = RUNNING_DOCKER ,
130131 timeout = 20. ,
131132 config = None ,
132- use_pypim_by_default = True
133+ use_pypim_by_default = True ,
134+ context = None
133135):
134136 """Start a new local DPF server at a given port and IP address.
135137
@@ -168,6 +170,10 @@ def start_local_server(
168170 use_pypim_by_default: bool, optional
169171 Whether to use PyPIM functionalities by default when a PyPIM environment is detected.
170172 Defaults to True.
173+ context: ServerContext, optional
174+ Defines the settings that will be used to load DPF's plugins.
175+ A DPF xml file can be used to list the plugins and set up variables. Default is
176+ `server_context.SERVER_CONTEXT`.
171177
172178 Returns
173179 -------
@@ -207,6 +213,9 @@ def start_local_server(
207213 else :
208214 docker_config .use_docker = False
209215
216+ if context is None :
217+ context = server_context .SERVER_CONTEXT
218+
210219 server = None
211220 n_attempts = 3
212221 timed_out = False
@@ -221,11 +230,11 @@ def start_local_server(
221230 server = server_type (
222231 ansys_path , ip , port , as_global = as_global , launch_server = True ,
223232 load_operators = load_operators , docker_config = docker_config , timeout = timeout ,
224- use_pypim = use_pypim )
233+ use_pypim = use_pypim , context = context )
225234 else :
226235 server = server_type (
227236 ansys_path , as_global = as_global ,
228- load_operators = load_operators , timeout = timeout )
237+ load_operators = load_operators , timeout = timeout , context = context )
229238 break
230239 except errors .InvalidPortError : # allow socket in use errors
231240 port += 1
@@ -249,7 +258,14 @@ def start_local_server(
249258 return server
250259
251260
252- def connect_to_server (ip = LOCALHOST , port = DPF_DEFAULT_PORT , as_global = True , timeout = 5 , config = None ):
261+ def connect_to_server (
262+ ip = LOCALHOST ,
263+ port = DPF_DEFAULT_PORT ,
264+ as_global = True ,
265+ timeout = 5 ,
266+ config = None ,
267+ context = None ,
268+ ):
253269 """Connect to an existing DPF server.
254270
255271 This method sets the global default channel that is then used for the
@@ -273,6 +289,10 @@ def connect_to_server(ip=LOCALHOST, port=DPF_DEFAULT_PORT, as_global=True, timeo
273289 passes, the connection fails.
274290 config: ServerConfig, optional
275291 Manages the type of server connection to use.
292+ context: ServerContext, optional
293+ Defines the settings that will be used to load DPF's plugins.
294+ A DPF xml file can be used to list the plugins and set up variables. Default is
295+ `server_context.SERVER_CONTEXT`.
276296
277297 Examples
278298 --------
@@ -293,17 +313,21 @@ def connect_to_server(ip=LOCALHOST, port=DPF_DEFAULT_PORT, as_global=True, timeo
293313 >>> #unspecified_server = dpf.connect_to_server(as_global=False)
294314
295315 """
316+ if context is None :
317+ context = server_context .SERVER_CONTEXT
296318
297319 def connect ():
298320 server_init_signature = inspect .signature (server_type .__init__ )
299321 if "ip" in server_init_signature .parameters .keys () \
300322 and "port" in server_init_signature .parameters .keys ():
301323 server = server_type (
302- ip = ip , port = port , as_global = as_global , launch_server = False
324+ ip = ip , port = port , as_global = as_global , launch_server = False ,
325+ context = context
303326 )
304327 else :
305328 server = server_type (
306- as_global = as_global
329+ as_global = as_global ,
330+ context = context
307331 )
308332 dpf .core ._server_instances .append (weakref .ref (server ))
309333 return server
0 commit comments