我有一个特定的程序...
我希望这个程序在任何ping不成功时都能打印出“not up”,当所有ping成功时,则打印“up”。函数
node_up = [0,0,0,0,0]
list_host = [ '10.0.2.12', '10.0.2.13', '10.0.2.14', '10.0.2.15', '10.0.2.16' ]
def node_check():
global node_up, list_host
for i in range( len(list_host) ):
try:
b = subprocess.check_output( ["ping", "-c", "4", "-w", "4", list_host[i] ] )
print b
node_up[i] = 1
print node_up
except subprocess.CalledProcessError, e:
print e.output
node_up[i] = 0
print node_up
thread.start_new_thread( node_check(), () )
while(1):
print "round"
if 0 in node_up:
print "not up"
print node_up
else:
print "up"
print node_up
print "round"
time.sleep(5)
我希望这个程序在任何ping不成功时都能打印出“not up”,当所有ping成功时,则打印“up”。函数
node_check()
正在执行,因为通过node_up
数组来输出正常。但是程序似乎从未执行检查node_up
的主要while(1)
。有人能指出我做错了什么吗?