Skip to content

Commit b11f62e

Browse files
authored
Merge pull request #209 from Labelbox/ms/improve-create-data-row
improve create data rows
2 parents 65acdd2 + d350070 commit b11f62e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

labelbox/client.py

Lines changed: 9 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,13 @@ 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+
elif response.status_code == 503:
308+
raise labelbox.exceptions.InternalServerError(response.text)
309+
301310
try:
302311
file_data = response.json().get("data", None)
303312
except ValueError as e: # response is not valid JSON

labelbox/schema/dataset.py

Lines changed: 7 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
@@ -34,6 +34,7 @@ class Dataset(DbObject, Updateable, Deletable):
3434
description = Field.String("description")
3535
updated_at = Field.DateTime("updated_at")
3636
created_at = Field.DateTime("created_at")
37+
row_count = Field.Int("row_count")
3738

3839
# Relationships
3940
projects = Relationship.ToMany("Project", True)
@@ -120,8 +121,11 @@ def upload_if_necessary(item):
120121
item = {DataRow.row_data: item_url, DataRow.external_id: item}
121122
return item
122123

123-
with ThreadPool(file_upload_thread_count) as thread_pool:
124-
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)]
125129

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

0 commit comments

Comments
 (0)