Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-While True循环直到满足条件_Python - Fatal编程技术网

Python-While True循环直到满足条件

Python-While True循环直到满足条件,python,Python,我需要一些帮助来完成这个循环函数。我需要这个函数来检查服务器是否处于运行状态。如果它处于运行状态,它将退出。如果服务器处于启动状态,它将打印启动状态并再次检查状态,直到服务器处于运行状态 一旦服务器处于运行状态,它将打印“服务器处于运行状态”并退出循环 根据安装的组件、库和类的不同,服务器最多需要8分钟才能进入运行状态。在某些情况下,它可能需要更多的时间,但我不想限制为8分钟的循环 最长时间为10分钟。10分钟后,如果它仍然没有处于运行状态,那么我们可以退出循环并打印“启动服务器时出现问题” d

我需要一些帮助来完成这个循环函数。我需要这个函数来检查服务器是否处于运行状态。如果它处于运行状态,它将退出。如果服务器处于启动状态,它将打印启动状态并再次检查状态,直到服务器处于运行状态

一旦服务器处于运行状态,它将打印“服务器处于运行状态”并退出循环

根据安装的组件、库和类的不同,服务器最多需要8分钟才能进入运行状态。在某些情况下,它可能需要更多的时间,但我不想限制为8分钟的循环

最长时间为10分钟。10分钟后,如果它仍然没有处于运行状态,那么我们可以退出循环并打印“启动服务器时出现问题”

def wait():
    acu=0
    while True:
        #serverStatus(deploymentTarget)
        appflag=0
        if state(deploymentTarget,'Server')=='RUNNING':
            appflag=1
        elif state(deploymentTarget,'Server')=='STARTING':
            appflag=2

        if appflag == 1 :
          # If appflag has value 1, it means that the server is active, so we exist the loop.
            break
        else :
            if appflag == 2 and (acu<30):
               serverState = serverStatus(deploymentTarget)
               java.lang.Thread.sleep(10000)
               acu = acu +1
               break
def wait():
acu=0
尽管如此:
#服务器状态(部署目标)
appflag=0
如果状态(deploymentTarget,'Server')=='RUNNING':
appflag=1
elif状态(deploymentTarget,'Server')=='STARTING':
appflag=2
如果appflag==1:
#如果appflag的值为1,则表示服务器处于活动状态,因此存在循环。
打破
其他:
如果appflag==2且(acu
从时间导入睡眠
def wait()
acu=0
而不是状态(deploymentTarget,'Server')=='RUNNING'和(acu<30):
acu+=1
如果状态(deploymentTarget,'Server')=='STARTING':
打印(“服务器正在启动”)
睡眠(10)
如果状态(deploymentTarget,'Server')=='RUNNING':
打印(“服务器正在运行”)
其他:
打印('启动服务器时出现问题')

顺便说一句,你不应该在python程序中混用java命令。

你想要什么?有问题吗?我认为有一些索引问题,请澄清。如果你使用Jython,那么使用java命令是完全可以的。好吧,我没想过。只是出于好奇:在这里使用java的sleep而不是python eq明智吗uivalent?我可以想象这将导致可避免的开销。嗨,丹尼尔,如果你认为使用Java会比Python更好,我可以试试。请更新这篇文章。谢谢…嗨,不,我没有这么说!我不知道在使用Jython时,你可以自由地混合使用Java和Python命令。但是,我担心这会导致性能损失。考虑到这一点,我想这并不重要,因为它只会在编译过程中发挥作用。嗨,Deniel,请您完成此脚本。脚本可以工作,但不会在服务器处于运行状态时停止。请您在循环过程中更新脚本,使其在服务器处于运行状态时停止。谢谢,哈里什。
from time import sleep

def wait()
    acu = 0
    while not state(deploymentTarget,'Server')=='RUNNING' and (acu < 30):
        acu += 1
        if state(deploymentTarget,'Server')=='STARTING':
            print("the server is starting")
        sleep(10)
    if state(deploymentTarget,'Server')=='RUNNING':
        print("the server is running")
    else:
        print('problem starting the server')