我有一个python脚本,我想只允许在一台机器上运行一次。如果它已经在运行,无论它在后台运行还是在不同的ssh会话中运行,我都希望它打印“Error,already running”。我将如何做到这一点?这是我的脚本。只允许一个python脚本实例?
import urllib, urllib2, sys
num = sys.argv[1]
print 'Calling'
phones = [
'http://phone1/index.htm',
'http://phone2/index.htm',
'https://phone3/index.htm',
'https://phone4/index.htm',
'https://phone5/index.htm'
]
data = urllib.urlencode({"NUMBER":num, "DIAL":"Dial", "active_line":1})
while 1:
for phone in phones:
try:
urllib2.urlopen(phone,data) # make call
urllib2.urlopen(phone+"?dialeddel=0") # clear logs
except: pass
P.S我正在使用CentOS 5。
如果你要发布只是一个链接,你可能想从它引用了一下为好。 – icktoofay
感谢您的提示。 – fatrock92
关于这一点的事情是,脚本是一个无限循环,所以它永远不会到达删除锁定脚本的末尾。 –