【问题标题】:While loop exits before all conditions are met [closed]在满足所有条件之前循环退出[关闭]
【发布时间】:2016-10-10 11:36:07
【问题描述】:

我在 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);

【问题讨论】:

  • @abadamso 注意到您使用了 java.lang.Thread,它看起来不像 python。你确定你有这个标签吗?
  • @ScottMermelstein:在我看来像Jython
  • while test 应该是 True 只要所有服务器都在'RUNNING',所以每个测试之间应该有“或”,因为即使一台服务器没有运行,循环也应该是循环的,为了完美实现我'将添加一个变量 - 循环计数器,以退出此循环并在所有服务器在一段时间内无法启动或 n 循环运行时调用异常

标签: python jython oracle12c wlst


【解决方案1】:

首先,这是 Jython 而不是 python。

第二次看:

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

仅当 none 状态为 == 'RUNNING' 时,条件才为 True。所以任何处于运行状态的服务器都会导致循环退出。如果您希望所有服务器在退出前启动,请使用or 而不是and

【讨论】:

  • 感谢您的回复。我对 Jython 的理解是它是带有 java 库的 python,因此得名 Jython。但感谢您强调我的错误。非常感谢!
猜你喜欢
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 2023-01-12
  • 2021-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
相关资源
最近更新 更多