I would like to get a List of all running Python Processes under Windows 7 (and later on Linux) in an acceptable Time. Based on the Results I would like to start additional new Processes which my main Application depends on.
I tried psutil from https://github.com/giampaolo/psutil:
import psutil
for process in psutil.process_iter():
if process.name == 'python.exe':
print(process)
This gave me good looking Results but running this took about one Minute!
I figured out that both iterating through all Processes with psutil.process_iter() and listing all Processes with psutil.get_pid_list() are acceptable fast, but obtaining each Processe’s Name for the Identification of Python Processes (which I would investigate further with process.cmdline) seems to be expensive.
Any Idea how to improve the Speed considerably or another Approach?
Use the windows function
EnumProcesses()(fromKernel32.dllorPsapi.dlldepending on your windows version) directly using ctypes.