LicenseContextManager#

class ansys.dpf.core.server_context.LicenseContextManager(increment_name: str = None, license_timeout_in_seconds: float = None, server=None)#

Can optionally be used to check out a license before using licensed DPF Operators.

Improves performance if you are using multiple Operators that require licensing. It can also be used to force checkout before running a script when few Ansys license increments are available. The license is checked in when the object is deleted.

Parameters:
  • increment_name (str, optional) – License increment to check out. To improve script efficiency, this license increment should be consistent with the increments required by the following Operators. If None, the first available increment of this list is checked out.

  • license_timeout_in_seconds (float, optional) – If an increment is not available by the maximum time set here, check out fails. Default is: ansys.dpf.core.runtime_config.RuntimeCoreConfig.license_timeout_in_seconds()

  • server (server.DPFServer, optional) – Server with the channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

Examples

Using a context manager >>> from ansys.dpf import core as dpf >>> dpf.set_default_server_context(dpf.AvailableServerContexts.premium) >>> field = dpf.Field() >>> field.append([0., 0., 0.], 1) >>> op = dpf.operators.filter.field_high_pass() >>> op.inputs.field(field) >>> op.inputs.threshold(0.0) >>> with dpf.LicenseContextManager() as lic: … out = op.outputs.field()

Using an instance >>> lic = dpf.LicenseContextManager() >>> op.inputs.field(field) >>> op.inputs.threshold(0.0) >>> out = op.outputs.field() >>> lic = None

Using a context manager and choosing license options >>> op.inputs.field(field) >>> op.inputs.threshold(0.0) >>> out = op.outputs.field() >>> op = dpf.operators.filter.field_high_pass() >>> op.inputs.field(field) >>> op.inputs.threshold(0.0) >>> with dpf.LicenseContextManager( … increment_name=”preppost”, license_timeout_in_seconds=1.) as lic: … out = op.outputs.field()

Notes

Available from 6.1 server version.

Overview#

release_data

Release the data.

status

Returns a string with the list of checked out increments.

__enter__

Enter the runtime context for the license context manager.

__exit__

Exit the runtime context for the license context manager.

__del__

Release the license when the instance is deleted.

Import detail#

from ansys.dpf.core.server_context import LicenseContextManager

Property detail#

property LicenseContextManager.status#

Returns a string with the list of checked out increments.

Return type:

str

Method detail#

LicenseContextManager.release_data()#

Release the data.

LicenseContextManager.__enter__()#

Enter the runtime context for the license context manager.

This method is called when the object is used within a with statement. It ensures that the license is checked out before the operations within the context block are executed.

Returns:

The current instance of the license context manager.

Return type:

LicenseContextManager

LicenseContextManager.__exit__(type, value, tb)#

Exit the runtime context for the license context manager.

This method is called at the end of a with statement. It ensures that the license is checked in and any resources allocated are released.

Parameters:
  • type (type or None) – The exception type, if an exception occurred within the context block, or None otherwise.

  • value (Exception or None) – The exception instance, if an exception occurred within the context block, or None otherwise.

  • tb (traceback or None) – The traceback object, if an exception occurred within the context block, or None otherwise.

Returns:

If True, suppresses the exception. Otherwise, the exception is propagated.

Return type:

bool

LicenseContextManager.__del__()#

Release the license when the instance is deleted.