:class:`LicenseContextManager` ============================== .. py: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. :param increment_name: 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. :type increment_name: str, optional :param license_timeout_in_seconds: If an increment is not available by the maximum time set here, check out fails. Default is: :py:func:`ansys.dpf.core.runtime_config.RuntimeCoreConfig.license_timeout_in_seconds` :type license_timeout_in_seconds: float, optional :param server: 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. :type server: server.DPFServer, optional .. rubric:: 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() .. rubric:: Notes Available from 6.1 server version. .. py:currentmodule:: LicenseContextManager Overview -------- .. tab-set:: .. tab-item:: Methods .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~release_data` - Release the data. .. tab-item:: Properties .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~status` - Returns a string with the list of checked out increments. .. tab-item:: Special methods .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~__enter__` - Enter the runtime context for the license context manager. * - :py:attr:`~__exit__` - Exit the runtime context for the license context manager. * - :py:attr:`~__del__` - Release the license when the instance is deleted. Import detail ------------- .. code-block:: python from ansys.dpf.core.server_context import LicenseContextManager Property detail --------------- .. py:property:: status Returns a string with the list of checked out increments. :rtype: str Method detail ------------- .. py:method:: release_data() Release the data. .. py:method:: __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. :rtype: LicenseContextManager .. py:method:: __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. :param type: The exception type, if an exception occurred within the context block, or None otherwise. :type type: type or None :param value: The exception instance, if an exception occurred within the context block, or None otherwise. :type value: Exception or None :param tb: The traceback object, if an exception occurred within the context block, or None otherwise. :type tb: traceback or None :returns: If True, suppresses the exception. Otherwise, the exception is propagated. :rtype: bool .. py:method:: __del__() Release the license when the instance is deleted.