0

我在 python 中有一个名为“exportjob”的工作(这个工作基本上是在外部应用程序中执行一个过程)。我需要 python 等待代码的执行,直到变量采用特定值。更准确地说:a) exportjob 的命令是:

exportJob = client.service.SubmitExportJob(USER, CLIENTID, PW, "MB_ExportSet_Portfolio", dt.date(2020, 4, 16), "Exporting Job", True)

b)然后我使用此命令获取此 exportjob 的状态(只需在命令中将 exportjob 变量传递给他)

status = client.service.GetExportJobStatus(USER, CLIENTID, PW, exportJob)

c) status 变量只立即返回以下值之一: status= 0 'Export completed succesfully', status<0 'Export failed', status>0 'Export is pending'

我想告诉python(如果状态> 0)等待状态= 0(或者如果状态<0,则停止程序)有人可以帮助我吗?

4

1 回答 1

0

你可以用一个简单的while循环来做到这一点

status = client.service.GetExportJobStatus(USER, CLIENTID, PW, exportJob)
while status > 0:
    status = client.service.GetExportJobStatus(USER, CLIENTID, PW, exportJob)
    sleep(0.1) #not needed but could be used to decrease number of iterations (pauses program for 0.1 seconds)
#new status is either =0 or <0 so you can execute the rest of your program
于 2020-04-20T18:24:11.293 回答