Process Control¶
Process launching and querying
-
mhi.enerplot.common.process.
process_pids
(*names)¶ 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.exe
andSkypeBackgroundHost.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.
Parameters: *names (str) – application filename patterns, without any path. Returns: A list of process name & process id pairs Return type: List[tuple]
-
mhi.enerplot.common.process.
is_running
(app)¶ Determine if there is an
app
process in the list of running processes.Application names may include the
%
wildcard. For example, the following query might find bothSkypeApp.exe
andSkypeBackgroundHost.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.
Parameters: app (str) – application filename, without any path. Returns: True if a process can be found, False otherwise. Return type: bool
-
mhi.enerplot.common.process.
tcp_ports_in_use
()¶ Find all TCP ports in use
Returns: Set of all ports in use by the TCP protocol Return type: Set[int]
-
mhi.enerplot.common.process.
unused_tcp_port
()¶ Find an available TCP ports in the dynamic/private range
Returns: an available TCP port Return type: int
-
mhi.enerplot.common.process.
listener_ports_by_pid
(*pid)¶ 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.
Parameters: *pid (int) – Processed ids Returns: a list of (addr, port, pid) tuples Return type: List[tuple]
-
mhi.enerplot.common.process.
listener_ports_by_name
(*names)¶ 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.exe
andSkypeBackgroundHost.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.
Parameters: *names (str) – application filename patterns, without any path. Returns: a list of (addr, port, pid, name) tuples Return type: List[tuple]
-
mhi.enerplot.common.process.
find_exe
(app, version=None, x64=None)¶ Find an application executable.
If no
version
is specified, the highest version available is used, with Alpha and Beta versions being considered the highest and second highest respectively. If nox64
flag 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 number such as ‘4.6.3’ or ‘Alpha’
- x64 (bool) –
True
for 64-bit version,False
for 32-bit version
Returns: the path to the executable
Return type: str
-
mhi.enerplot.common.process.
launch
(*args, options=None, **kwargs)¶ Launch an application process.
All
{keyword}
format codes in the list ofargs
strings are replaced by the value in the correspondingoptions
dictionary and/orkwargs
key-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.exe
passing the arguments/silent:True
and/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
¶ Keyword=Value Effect launch_minimized=True
process started with SW_SHOWMINNOACTIVE
launch_minimized=False
process started with SW_SHOWNOACTIVATE
debug=True
process is not started, command line printed