我正在使用 python 2.7 和 windows 7 64 位。我想知道任务管理器/进程中的进程 (python.exe) 是否正在运行。 我经历了http://www.videntity.com/2010/05/check-to-make-sure-a-process-is-running-and-restart-it-if-its-not-a-recipe-in-python/ , 但不适用于 Windows。
请您参考如下方法:
您链接的页面使用 os.popen()( official docs here )
在 Windows 中,您应该使用“tasklist”作为 os.popen() 的参数,而不是“ps -Af”
例如
>>> import os
>>> tmp = os.popen("tasklist").read() # it would return a str type
>>> "python.exe" in tmp
True
