检查是否有同名py文件在运行

import psutil
import os

def is_running(script):
for q in psutil.process_iter():
if q.name().startswith('python'):
if len(q.cmdline())>1 and script in q.cmdline()[1] and q.pid !=os.getpid():
print("'{}' Process is already running".format(script))
return True

return False


if not is_running("111.py"):
n = input("What is Your Name? ")
print ("Hello " + n)
posted @ 2019-06-10 16:45  C,python,linux,java  阅读(427)  评论(0编辑  收藏  举报