Pergunta

I am using python 2.7 and windows 7 64 bit. I want to know whether a process(python.exe) is running or not in task manager/Processes. I had gone through http://www.videntity.com/2010/05/check-to-make-sure-a-process-is-running-and-restart-it-if-its-not-a-recipe-in-python/, but it is not for windows.

Foi útil?

Solução

The page you linked uses os.popen()(official docs here)

In windows, you should use "tasklist" as arg for os.popen(), rather than "ps -Af"

e.g.

>>> import os
>>> tmp = os.popen("tasklist").read()  # it would return a str type
>>> "python.exe" in tmp
True

Outras dicas

Here's how I do it with win32:

from win32com.client import GetObject
WMI = GetObject('winmgmts:')
processes = WMI.InstancesOf('Win32_Process')

if "python.exe" in [process.Properties_('Name').Value for process in processes]:
    #do the thing

You should be able to see your process in the Background Processes in the processes tab of the task manager with the name pythonw.exe(64 bit)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top