How to get all running Python processes under Windows at an acceptable time?

I would like to get a list of all running Python processes under Windows 7 (and later Linux) at an acceptable time. Based on the results, I would like to start new new Processes on which my main application depends.

I tried psutil from https://github.com/giampaolo/psutil :

import psutil for process in psutil.process_iter(): if process.name == 'python.exe': print(process) 

It gave me good results, but launching it took about one minute!

I realized that iterating through all processes with psutil.process_iter () and listing all processes with psutil.get_pid_list () are acceptable quickly, but getting each Process Name to identify Python processes (which I would investigate further using process.cmdline ) seems to be , expensive.

Any idea how to significantly improve speed or another approach?

+4
source share
1 answer

Use the windows function EnumProcesses() (from Kernel32.dll or Psapi.dll depending on your version of Windows) using ctypes .

+3
source

Source: https://habr.com/ru/post/1435778/


All Articles