2016-06-09 106 views
-5

我在python中編寫了一個腳本來啓動服務器。 在循環中,我正在檢查它們的狀態,以確保在前進之前所有服務器都已啓動。while循環在滿足所有條件前退出

但不知何故,所有條件之前退出循環得到滿足。

爲什麼發生這種情況的任何想法?

#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

@abadamso注意到您使用的java.lang.Thread,其中似乎並不很喜歡蟒蛇。你確定你有這個標記的權利? –

+2

@ScottMermelstein:對我來說看起來像[Jython](http://www.jython.org/)。 – user2357112

+1

,只要所有服務器都是'RUNNING',測試應該是True,因此每個測試之間應該有「或」,因爲即使一個服務器沒有運行,循環也應該循環,爲了完美實現,我將添加一個變量 - 循環計數器,退出此循環並調用異常,如果所有服務器在一段時間內無法恢復或正常循環運行 – Jerzyk

回答

3

首先,這是Jython不是python。

其次看看:

while (osb2State!='RUNNING') and (osb3State!='RUNNING') and (osb4State!='RUNNING') and (osb5State!='RUNNING') and (osb6State!='RUNNING') : 

的條件是唯一的真要是的國家都沒有是==「運行」。所以任何處於運行狀態的服務器都會導致該循環退出。如果你想所有服務器待漲退出前,使用orand

+0

感謝您的回覆。我對Jython的理解是,它是帶有java庫的python,因此名稱爲Jython。但謝謝你突出我的錯誤。非常感激! –

相關問題