def get_licdebug_name(): """Get license client log file name. This file change the name according to the ANSYS version and the type of license requested (``$appname``). * For ANSYS version 22.1 and above: ``licdebug.$hostname.$appname.$version.out`` * For ANSYS version 21.2 and below: ``licdebug.$appname.$version.out`` where: * ``$hostname`` is the name of the machine. * ``$appname`` is the name of the feature used by the license client. Eg. 'FEAT_ANSYS' * ``$version`` is the version of ANSYS. Eg 211 for version 21.1. Returns ------- str licdebug log file complete name. """ # Licdebug name convention: # - For version 22.1 and above: `licdebug.$hostname.$appname.$version.out` # - For version 21.2 and below: `licdebug.$appname.$version.out` from ansys.mapdl.core.launcher import _version_from_path, get_ansys_path name = "licdebug" hostname = socket.gethostname() appname = APP_NAME # This is the type of license my client requests (Windows 10, 2021R2) version = _version_from_path(get_ansys_path(allow_input=False)) ending = "out" if version < 221: parts = (name, appname, version, ending) else: parts = (name, hostname, appname, version, ending) return ".".join([str(each_part) for each_part in parts])
def __init__( self, n_instances, wait=True, run_location=None, port=MAPDL_DEFAULT_PORT, progress_bar=True, restart_failed=True, remove_temp_files=True, **kwargs, ): """Initialize several instances of mapdl""" self._instances = [] self._root_dir = run_location kwargs["remove_temp_files"] = remove_temp_files kwargs["mode"] = "grpc" self._spawn_kwargs = kwargs # verify that mapdl is 2021R1 or newer if "exec_file" in kwargs: exec_file = kwargs["exec_file"] else: # get default executable exec_file = get_ansys_path() if exec_file is None: raise FileNotFoundError( "Invalid exec_file path or cannot load cached " "ansys path. Enter one manually using " "exec_file=<path to executable>") if _version_from_path(exec_file) < 211: raise VersionError( "LocalMapdlPool requires MAPDL 2021R1 or later.") # grab available ports ports = available_ports(n_instances, port) if self._root_dir is not None: if not os.path.isdir(self._root_dir): os.makedirs(self._root_dir) self._instances = [] self._active = True # used by pool monitor n_instances = int(n_instances) if n_instances < 2: raise ValueError( "Must request at least 2 instances to create a pool.") pbar = None if wait and progress_bar: pbar = tqdm(total=n_instances, desc="Creating Pool") # initialize a list of dummy instances self._instances = [None for _ in range(n_instances)] # threaded spawn threads = [ self._spawn_mapdl(i, ports[i], pbar, name=f'Instance {i}') for i in range(n_instances) ] if wait: [thread.join() for thread in threads] # check if all clients connected have connected if len(self) != n_instances: n_connected = len(self) warnings.warn( f"Only %d clients connected out of %d requested" % (n_connected, n_instances)) if pbar is not None: pbar.close() # monitor pool if requested if restart_failed: self._pool_monitor_thread = self._monitor_pool( name='Monitoring_Thread') self._verify_unique_ports()
def test_catch_version_from_path(): with pytest.raises(RuntimeError): _version_from_path("abc")
def test_version_from_path(path_data): exec_file, version = path_data assert _version_from_path(exec_file) == version