cfx_connection#
Module for CFX connection functionality.
Classes:
|
Encapsulates a CFX connection. |
|
Stores CFX connection properties, including connection IP address, port, UDS address, and password; CFX Engine working directory, process ID, and hostname; and whether CFX was launched in a Docker container. |
|
Indicates the error state of the connected CFX client. |
Monitors a CFX session. |
Exceptions:
Raised when the gRPC connection is insecure. |
|
Raised when the port is not provided. |
|
Raised when the |
|
Raised when invalid |
Functions:
|
Get the Docker container object. |
- class ansys.cfx.core.cfx_connection.CFXConnection(ip: str | None = None, port: int | None = None, address: str | None = None, password: str | None = None, channel: Channel | None = None, allow_remote_host: bool = False, certificates_folder: str | None = None, insecure_mode: bool = False, cleanup_on_exit: bool = True, start_transcript: bool = False, remote_instance: Instance | None = None, launcher_args: Dict[str, Any] | None = None, inside_container: bool | None = None)#
Bases:
objectEncapsulates a CFX connection.
Methods
exit()
Close the CFX connection and exit CFX.
Methods:
__init__([ip, port, address, password, ...])Initialize a session.
create_grpc_service(service, *args)Create a gRPC service.
exit([timeout, timeout_force, wait])Close the CFX connection and exit CFX.
Terminate the CFX client immediately, which results in losing unsaved progress and data.
Register a callback to run with the finalizer.
wait_process_finished([wait])Return
Trueif local CFX processes have finished,Falseif they are still running when wait limit (default 60 seconds) is reached.Attributes:
CFX build information.
- __init__(ip: str | None = None, port: int | None = None, address: str | None = None, password: str | None = None, channel: Channel | None = None, allow_remote_host: bool = False, certificates_folder: str | None = None, insecure_mode: bool = False, cleanup_on_exit: bool = True, start_transcript: bool = False, remote_instance: Instance | None = None, launcher_args: Dict[str, Any] | None = None, inside_container: bool | None = None)#
Initialize a session.
- Parameters:
- ip
str, default:None IP address to connect to an existing CFX instance. This parameter is used only when
channelisNone. When this parameter isNone,"127.0.0.1"is used. The IP address can also be set by thePYCFX_CFX_IP=<ip>environment variable.- port
int, default:None Port to connect to an existing CFX instance. This parameter is used only when
channelisNone. The port can also be set by thePYCFX_CFX_PORT=<port>environment variable.- address
str, default:None Address to connect to an existing CFX instance.
- password
str, default:None Password to connect to an existing CFX instance.
- channel
grpc.Channel, default:None gRPC channel to use to connect to an existing CFX instance. The
ipandportparameters are ignored when a gRPC channel is specified.- allow_remote_hostbool, default:
False Whether to allow connecting to a remote CFX instance.
- certificates_folder
str, default:None Path to the folder containing TLS certificates for CFX’s gRPC server.
- insecure_modebool, default:
False Whether to connect CFX’s gRPC server in insecure mode without TLS. This mode is not recommended. For more information on the implications and usage of insecure mode, see the CFX documentation.
- cleanup_on_exitbool, default:
True Whether to shut down the connected CFX session when PyCFX is exited or the exit() function is called on the session instance.
- start_transcriptbool, default:
False Whether to start the CFX transcript in the client. The CFX transcript can be started and stopped subsequently using method calls on the session object.
- remote_instance
ansys.platform.instancemanagement.Instance Corresponding remote instance when CFX is launched through PyPIM. This instance is deleted when calling the
Session.exit()function.- inside_container: bool, default: None
Whether the CFX session that is being connected to is running inside a Docker container.
- ip
- Raises:
PortNotProvidedIf port is not provided.
- create_grpc_service(service, *args)#
Create a gRPC service.
- Parameters:
- service
Any Service class.
- args
Any Additional arguments.
- service
- Returns:
AnyService object.
- exit(timeout: float | None = None, timeout_force: bool = True, wait: float | int | bool | None = False) None#
Close the CFX connection and exit CFX.
- Parameters:
- timeout
float, default:None Time in seconds before considering that the exit request has timed out. If omitted or specified as
None, the request does not time out and locks up the interpreter while waiting for a response. The request returns earlier if it succeeds earlier.- timeout_forcebool, default:
True Whether to attempt to terminate the CFX process if the exit request reached timeout. If no timeout is set, this option is ignored. Executes the
force_exit()orforce_exit_container()function to terminate the CFX process, depending on how CFX was launched.- wait
float,intor bool, default:False Whether to wait for local CFX processes to finish completely before proceeding. If omitted or specified as
False, the request proceeds as usual without waiting for the CFX processes to finish. If this parameter is set toTruethe request waits for up to 60 seconds by default. The wait limit can be specified as a float or integer value. If the wait limit is reached, the request forcefully terminate the CFX process. If it is set to wait, it returns as soon as the processes completely finishes. It does not work for the remote CFX processes.
- timeout
Notes
The
PYCFX_TIMEOUT_FORCE_EXITenvironment variable can also be used to specify the number of seconds and alter the defaulttimeoutvalue. Setting this environment variable to a non-number value, such asOFF, returns this function to the default behavior. Note that the environment variable is ignored if a timeout is specified when calling this function.Examples
>>> import ansys.cfx.core as pycfx >>> session = pycfx.launch_cfx() >>> session.exit()
- force_exit()#
Terminate the CFX client immediately, which results in losing unsaved progress and data.
Notes
If the CFX session is responsive, using the
exit()function is preferred.Examples
>>> import ansys.cfx.core as pycfx >>> session = pycfx.launch_cfx() >>> session.force_exit()
- register_finalizer_cb(cb)#
Register a callback to run with the finalizer.
- wait_process_finished(wait: float | int | bool = 60)#
Return
Trueif local CFX processes have finished,Falseif they are still running when wait limit (default 60 seconds) is reached. Immediately cancels and returnsNoneifwaitis set toFalse.- Parameters:
- Raises:
UnsupportedRemoteCFXInstanceIf current CFX instance is running remotely.
WaitTypeErrorIf
waitis specified improperly.
- class ansys.cfx.core.cfx_connection.CFXConnectionProperties(ip: str | None = None, port: int | None = None, address: str | None = None, password: str | None = None, engine_pwd: str | None = None, engine_pid: int | None = None, engine_host: str | None = None, cfx_host_pid: int | None = None, inside_container: bool | Container | None = None)#
Bases:
objectStores CFX connection properties, including connection IP address, port, UDS address, and password; CFX Engine working directory, process ID, and hostname; and whether CFX was launched in a Docker container.
Examples
These properties are also available through the session object and can be accessed:
>>> import ansys.cfx.core as pycfx >>> session = pycfx.launch_cfx() >>> session.connection_properties.list_names() ['ip', 'port', 'address', 'password', 'engine_pwd', 'engine_pid', 'engine_host', 'cfx_host_pid', 'inside_container'] >>> session.connection_properties.ip 'localhost'
Methods:
__init__([ip, port, address, password, ...])Get a list of all property names.
Get a dictionary with all property names and values.
Attributes:
The UDS address of the connected CFX session.
The process ID of the CFX engine (same as engine_pid).
The hostname of the machine where the CFX engine is running.
The process ID of the CFX engine (same as cfx_host_pid).
The CFX engine working directory.
Whether the connected CFX session is running inside a Docker container.
The IP address of the connected CFX session.
The password used to connect to the CFX session.
The port of the connected CFX session.
- __init__(ip: str | None = None, port: int | None = None, address: str | None = None, password: str | None = None, engine_pwd: str | None = None, engine_pid: int | None = None, engine_host: str | None = None, cfx_host_pid: int | None = None, inside_container: bool | Container | None = None) None#
- class ansys.cfx.core.cfx_connection.ErrorState(name: str = '', details: str = '')#
Bases:
objectIndicates the error state of the connected CFX client.
Examples
>>> import ansys.cfx.core as pycfx >>> session = pycfx.launch_cfx() >>> session._cfx_connection._error_state.set("test", "test details") >>> session._cfx_connection._error_state.name 'test' >>> session._cfx_connection._error_state.details 'test details' >>> session._cfx_connection._error_state.clear() >>> session._cfx_connection._error_state.name ''
Methods:
__init__([name, details])Initialize the error state object.
clear()Clear the current error state, emptying the error name and details properties.
set(name, details)Set the error state name and details to new values.
Attributes:
- clear()#
Clear the current error state, emptying the error name and details properties.
- property details#
Additional details of the error state.
- property name#
Name of the error state.
- exception ansys.cfx.core.cfx_connection.InsecureGrpcWarning#
Bases:
WarningRaised when the gRPC connection is insecure.
- class ansys.cfx.core.cfx_connection.MonitorThread#
Bases:
ThreadMonitors a CFX session.
A daemon thread that ensures cleanup of session objects and shut down of non-daemon threads.
- Attributes:
- cbs
List[Callable] Cleanup and shutdown functions.
- cbs
Methods:
- __init__()#
Initialize an instance of the
MonitorThreadclass.
- exception ansys.cfx.core.cfx_connection.PortNotProvided#
Bases:
ValueErrorRaised when the port is not provided.
Methods:
__init__()- __init__()#
- exception ansys.cfx.core.cfx_connection.UnsupportedRemoteCFXInstance#
Bases:
ValueErrorRaised when the
wait_process_finishedmethod does not support a remote CFX session.Methods:
__init__()- __init__()#
- exception ansys.cfx.core.cfx_connection.WaitTypeError#
Bases:
TypeErrorRaised when invalid
waittype is provided.Methods:
__init__()- __init__()#
- ansys.cfx.core.cfx_connection.get_container(container_id_or_name: str) bool | Container | None#
Get the Docker container object.
- Returns:
Notes
See Docker container for more information.