File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,8 @@ def upload_file(self, path: str) -> str:
254
254
filename = filename ,
255
255
content_type = content_type )
256
256
257
+ @retry .Retry (predicate = retry .if_exception_type (
258
+ labelbox .exceptions .InternalServerError ))
257
259
def upload_data (self ,
258
260
content : bytes ,
259
261
filename : str = None ,
@@ -298,6 +300,11 @@ def upload_data(self,
298
300
"1" : (filename , content , content_type ) if
299
301
(filename and content_type ) else content
300
302
})
303
+
304
+ if response .status_code == 502 :
305
+ error_502 = '502 Bad Gateway'
306
+ raise labelbox .exceptions .InternalServerError (error_502 )
307
+
301
308
try :
302
309
file_data = response .json ().get ("data" , None )
303
310
except ValueError as e : # response is not valid JSON
Original file line number Diff line number Diff line change 2
2
import json
3
3
import logging
4
4
from itertools import islice
5
- from multiprocessing . dummy import Pool as ThreadPool
5
+ from concurrent . futures import ThreadPoolExecutor , as_completed
6
6
import time
7
7
import ndjson
8
8
from io import StringIO
@@ -121,8 +121,11 @@ def upload_if_necessary(item):
121
121
item = {DataRow .row_data : item_url , DataRow .external_id : item }
122
122
return item
123
123
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 )]
126
129
127
130
def convert_item (item ):
128
131
# Don't make any changes to tms data
You can’t perform that action at this time.
0 commit comments