Process Control#
Process launching and querying
- mhi.common.process.process_pids(*names: str) List[Tuple[str, int]]#
Return the process id’s of any process with the given executable names.
Application names may include the
%wildcard. For example, the following query might find bothSkypeApp.exeandSkypeBackgroundHost.exe:process_ids('skype%.exe')
Since applications may terminate and can be started at any time, the returned value is obsolete immediately upon being returned.
- mhi.common.process.is_running(app_name: str) bool#
Determine if there is an
appprocess in the list of running processes.Application names may include the
%wildcard. For example, the following query might find bothSkypeApp.exeandSkypeBackgroundHost.exe:is_running('skype%.exe')
Since applications may terminate and can be started at any time, the returned value is obsolete immediately upon being returned.
- mhi.common.process.host_addresses(host: str) Set[str]#
Convert a host name into one or more IP address (ie, IPv4 & IPv6)
- mhi.common.process.is_local_host(host: str) bool#
Does the given hostname represent the local host?
Returns True if the given ‘host’ is a public IP address of the host, a loopback address, an IPADDR_ANY-type address, or a symbolic name that represents any of these.
- mhi.common.process.host_filter(host: str)#
Return a filter function to filter an iterable of
AddressPortPidorAddressPortPidApplisteners against the given host
- mhi.common.process.tcp_ports_in_use() Set[int]#
Find all TCP ports in use
- Returns:
Set of all ports in use by the TCP protocol
- Return type:
Set[int]
- mhi.common.process.unused_tcp_port(ports: range | None = None) int#
Find an available TCP ports in the specified range. If no range is given, the dynamic/private range (0xC000–0xFFFF) is used.
- Returns:
an available TCP port
- Return type:
- mhi.common.process.listener_ports_by_pid(*pid: int) List[AddressPortPid]#
Find all listener ports opened by processes with the given PIDs.
Since applications may terminate and can be started at any time, as well as open and close ports at any time, the returned value is obsolete immediately upon being returned.
- mhi.common.process.listener_ports_by_name(*names: str) List[AddressPortPidApp]#
Find all listener ports opened by processes with the given executable name.
Application names may include the
%wildcard. For example, the following query might find both listener ports opened by bothSkypeApp.exeandSkypeBackgroundHost.exe:listener_ports_by_name('skype%.exe')
Since applications may terminate and can be started at any time, as well as open and close ports at any time, the returned value is obsolete immediately upon being returned.
- mhi.common.process.versions(app_name: str) List[Tuple[str, bool]]#
Find the installed versions of an MHI application.
- Returns:
List of tuples of version and bit-size
- Return type:
List[Tuple]
- mhi.common.process.find_exe(app_name: str, version: str | None = None, x64: bool | None = None, minimum: str | None = None, maximum: str | None = None, allow_alpha: bool = False, allow_beta: bool = False) str | None#
Find an MHI application executable.
If no
versionis specified, the highest version available is used, with Alpha and Beta versions being considered the highest and second highest respectively. If nox64flag is given, a 32-bit or 64-bit version may be returned, with preference given to 64-bit versions.- Parameters:
app (str) – name of the application (without any extension)
version (str) – application version such as ‘5.0.1’ or ‘5.1 (Beta)’
x64 (bool) –
Truefor 64-bit version,Falsefor 32-bit versionminimum (str) – The lowest allowable version, such as ‘5.0’
maximum (str) – The highest allowable version, such as ‘5.0.9’
- Returns:
the path to the executable
- Return type:
Added in version 2.1:
minimum,maximum,allow_alpha&allow_betaparameters.Changed in version 2.4.5:
allow_alpha,allow_betaparameters are no longer supported.Changed in version 3.0.3:
allow_betaparameter is once again supported.
- mhi.common.process.launch(*args: str, options: Dict[str, Any] | None = None, **kwargs)#
Launch an application process.
All
{keyword}format codes in the list ofargsstrings are replaced by the value in the correspondingoptionsdictionary and/orkwargskey-value argument pairs.For example:
launch("C:\{dir}\{name}.exe", "/silent:{silent}", "/title:{title!r}", dir="temp", name="app", silent=True, title="Hello world")
will launch
C:\temp\app.exepassing the arguments/silent:Trueand/title:'Hello world'- Parameters:
*args (str) – the application and the arguments for the application
options – values which may be substituted in the application arguments
**kwargs – additional substitution values
- Returns:
The subprocess handle
Special keyword arguments# Keyword=Value
Effect
minimize=Trueprocess started with
SW_SHOWMINNOACTIVEminimize=Falseprocess started with
SW_SHOWNOACTIVATEdebug=Trueprocess is not started, command line printed
- mhi.common.process.report(installed=True, minimums=False, running=True, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)#
Report known, installed MHI products