【问题标题】:How to instruct python to wait for a job to run until the variable takes on a certain value如何指示python等待作业运行,直到变量取特定值
【发布时间】:2020-08-03 03:34:16
【问题描述】:

我在 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= 0 'Export completed succesfully', status0 'Export is pending'

我想告诉python(如果状态>0)等待状态=0(或者如果状态

【问题讨论】:

  • while 循环怎么样?

标签: python python-3.x task scheduled-tasks


【解决方案1】:

您可以通过一个简单的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

【讨论】:

  • 非常感谢,现在可以正常使用了。如果可能的话,我能再问你一个问题吗?提交作业并成功导出状态后不久,我得到了另一个作业的文件,如下所示:dataWrk = client.service.GetExportJob(USER,CLIENTID,PW,exportJob)。我需要将 dataWrk 链接到一个 zip 对象文件,然后将其解压缩。我在肥皂 SUDS JURKO 下工作
  • 没问题。但是因为我从来没有在 python 中使用过 SOAP,所以恐怕我帮不上什么忙。如果您询问有关发送 zip 对象的问题,可以查看 How to send a file through Soap in python?。
猜你喜欢
  • 1970-01-01
  • 2022-11-25
  • 2022-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多