我在python中编写了一个脚本来启动服务器。 在循环中,我要检查它们的状态,以确保所有服务器都已启动,然后再继续。
但不知怎的,循环在满足所有条件之前退出。
关于为什么会发生这种情况的任何想法?
#check if all servers are RUNNING
while (osb2State!='RUNNING') and (osb3State!='RUNNING') and (osb4State!='RUNNING') and (osb5State!='RUNNING') and (osb6State!='RUNNING') :
cd('domainRuntime:/ServerLifeCycleRuntimes/'+sOSB2);
osb2State = cmo.getState();
if osb2State == 'ADMIN':
resume(sOSB2);
cd('domainRuntime:/ServerLifeCycleRuntimes/'+sOSB3);
osb3State = cmo.getState();
if osb3State == 'ADMIN':
resume(sOSB3);
cd('domainRuntime:/ServerLifeCycleRuntimes/'+sOSB4);
osb4State = cmo.getState();
if osb4State == 'ADMIN':
resume(sOSB4);
cd('domainRuntime:/ServerLifeCycleRuntimes/'+sOSB5);
osb5State = cmo.getState();
if osb5State == 'ADMIN':
resume(sOSB5);
cd('domainRuntime:/ServerLifeCycleRuntimes/'+sOSB6);
osb6State = cmo.getState();
if osb6State == 'ADMIN':
resume(sOSB6);
java.lang.Thread.sleep(5000);
答案 0 :(得分:3)
首先,这是Jython而不是python。
第二看看:
while (osb2State!='RUNNING') and (osb3State!='RUNNING') and (osb4State!='RUNNING') and (osb5State!='RUNNING') and (osb6State!='RUNNING') :
如果状态 none = =' RUNNING',则条件仅为True。因此,任何处于运行状态的服务器都将导致循环退出。如果您希望所有服务器在退出之前启动,请使用or
而不是and
。