Python While True循环直到条件为m

2024-10-01 07:41:40 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

根据安装的组件、库和类,服务器最多需要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

谢谢


Tags: the函数服务器ifserver状态时间组件
1条回答
网友
1楼 · 发布于 2024-10-01 07:41:40
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')

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

相关问题 更多 >