Skip to content

Commit 9e95e3f

Browse files
author
Matt Sokoloff
committed
add retry logic
1 parent 1ef9ca1 commit 9e95e3f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

labelbox/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ def upload_file(self, path: str) -> str:
254254
filename=filename,
255255
content_type=content_type)
256256

257+
@retry.Retry(predicate=retry.if_exception_type(
258+
labelbox.exceptions.InternalServerError))
257259
def upload_data(self,
258260
content: bytes,
259261
filename: str = None,
@@ -298,6 +300,11 @@ def upload_data(self,
298300
"1": (filename, content, content_type) if
299301
(filename and content_type) else content
300302
})
303+
304+
if response.status_code == 502:
305+
error_502 = '502 Bad Gateway'
306+
raise labelbox.exceptions.InternalServerError(error_502)
307+
301308
try:
302309
file_data = response.json().get("data", None)
303310
except ValueError as e: # response is not valid JSON

labelbox/schema/dataset.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import logging
44
from itertools import islice
5-
from multiprocessing.dummy import Pool as ThreadPool
5+
from concurrent.futures import ThreadPoolExecutor, as_completed
66
import time
77
import ndjson
88
from io import StringIO
@@ -121,8 +121,11 @@ def upload_if_necessary(item):
121121
item = {DataRow.row_data: item_url, DataRow.external_id: item}
122122
return item
123123

124-
with ThreadPool(file_upload_thread_count) as thread_pool:
125-
items = thread_pool.map(upload_if_necessary, items)
124+
with ThreadPoolExecutor(file_upload_thread_count) as executor:
125+
futures = [
126+
executor.submit(upload_if_necessary, item) for item in items
127+
]
128+
items = [future.result() for future in as_completed(futures)]
126129

127130
def convert_item(item):
128131
# Don't make any changes to tms data

0 commit comments

Comments
 (0)