【发布时间】:2017-08-24 10:31:06
【问题描述】:
我正在用 Python 为 Azure Batch 编写任务管理器。 当我运行管理器并将作业添加到指定的 Azure Batch 帐户时,我会这样做:
- 检查指定的job id是否已经存在
- 如果是,删除作业
- 创建作业
不幸的是,我在第 2 步和第 3 步之间失败了。这是因为,即使我为指定的作业发出删除命令并检查 Azure Batch 帐户中是否没有具有相同 ID 的作业,我也会收到 BatchErrorException,如当我尝试再次创建作业时如下:
Exception encountered:
The specified job has been marked for deletion and is being garbage collected.
我用来删除作业的代码如下:
def deleteJob(self, jobId):
print("Delete job [{}]".format(jobId))
self.__batchClient.job.delete(jobId)
# Wait until the job is deleted
# 10 minutes timeout for the operation to succeed
timeout = datetime.timedelta(minutes=10)
timeout_expiration = datetime.datetime.now() + timeout
while True:
try:
# As long as we can retrieve data related to the job, it means it is still deleting
self.__batchClient.job.get(jobId)
except batchmodels.BatchErrorException:
print("Job {jobId} deleted correctly.".format(
jobId = jobId
))
break
time.sleep(2)
if datetime.datetime.now() > timeout_expiration:
raise RuntimeError("ERROR: couldn't delete job [{jobId}] within timeout period of {timeout}.".format(
jobId = jobId
, timeout = timeout
))
我尝试检查 Azure SDK,但找不到可以准确告诉我作业何时被完全删除的方法。
【问题讨论】:
标签: python azure azure-batch