Skip to content

Commit 08d1767

Browse files
authored
Merge pull request #651 from corynezinstitchfix/label-export-timeout-fix
Fix timeout logic
2 parents c9f561f + e8673e8 commit 08d1767

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

labelbox/schema/project.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def export_queued_data_rows(
205205
{exportQueuedDataRows(data:{projectId: $%s , includeMetadataInput: $%s}) {downloadUrl createdAt status} }
206206
""" % (id_param, metadata_param, id_param, metadata_param)
207207
sleep_time = 2
208+
start_time = time.time()
208209
while True:
209210
res = self.client.execute(query_str, {
210211
id_param: self.uid,
@@ -219,8 +220,8 @@ def export_queued_data_rows(
219220
elif res["status"] == "FAILED":
220221
raise LabelboxError("Data row export failed.")
221222

222-
timeout_seconds -= sleep_time
223-
if timeout_seconds <= 0:
223+
current_time = time.time()
224+
if current_time - start_time > timeout_seconds:
224225
raise LabelboxError(
225226
f"Unable to export data rows within {timeout_seconds} seconds."
226227
)
@@ -328,6 +329,7 @@ def _validate_datetime(string_date: str) -> bool:
328329
{exportLabels(data:{projectId: $%s%s}) {downloadUrl createdAt shouldPoll} }
329330
""" % (id_param, id_param, filter_param)
330331

332+
start_time = time.time()
331333
while True:
332334
res = self.client.execute(query_str, {id_param: self.uid})
333335
res = res["exportLabels"]
@@ -340,8 +342,8 @@ def _validate_datetime(string_date: str) -> bool:
340342
response.raise_for_status()
341343
return response.json()
342344

343-
timeout_seconds -= sleep_time
344-
if timeout_seconds <= 0:
345+
current_time = time.time()
346+
if current_time - start_time > timeout_seconds:
345347
return None
346348

347349
logger.debug("Project '%s' label export, waiting for server...",

0 commit comments

Comments
 (0)