10
10
import meorg_client .endpoints as endpoints
11
11
import meorg_client .exceptions as mx
12
12
import meorg_client .utilities as mu
13
+ import meorg_client .parallel as meop
13
14
import mimetypes as mt
14
15
from pathlib import Path
15
- from multiprocessing import Pool
16
16
17
17
18
18
class Client :
@@ -217,7 +217,9 @@ def logout(self):
217
217
self .headers .pop ("X-User-Id" , None )
218
218
self .headers .pop ("X-Auth-Token" , None )
219
219
220
- def upload_files_parallel (self , files : Union [str , Path , list ], n : int = 2 ):
220
+ def upload_files_parallel (
221
+ self , files : Union [str , Path , list ], n : int = 2 , attach_to : str = None
222
+ ):
221
223
"""Upload files in parallel.
222
224
223
225
Parameters
@@ -226,6 +228,8 @@ def upload_files_parallel(self, files: Union[str, Path, list], n: int = 2):
226
228
A path to a file, or a list of paths.
227
229
n : int, optional
228
230
Number of threads to use, by default 2.
231
+ attach_to : str, optional
232
+ Module output id to attach to, by default None.
229
233
230
234
Returns
231
235
-------
@@ -242,21 +246,25 @@ def upload_files_parallel(self, files: Union[str, Path, list], n: int = 2):
242
246
243
247
# Do the parallel upload
244
248
responses = None
245
- with Pool (processes = n ) as pool :
246
- responses = pool .map (self .upload_files , files )
249
+ responses = meop .parallelise (
250
+ self .upload_files , n , files = files , attach_to = attach_to
251
+ )
247
252
248
253
return responses
249
254
250
255
def upload_files (
251
256
self ,
252
257
files : Union [str , Path ],
258
+ attach_to : str = None ,
253
259
) -> Union [dict , requests .Response ]:
254
260
"""Upload a file.
255
261
256
262
Parameters
257
263
----------
258
264
files : path-like, list
259
265
Path to the file, or a list containing paths.
266
+ attach_to : str, optional
267
+ Optional model_output_id to attach the files to, by default None
260
268
261
269
Returns
262
270
-------
@@ -309,6 +317,13 @@ def upload_files(
309
317
for fd in payload :
310
318
fd [1 ][1 ].close ()
311
319
320
+ # Automatically attach to a model output
321
+ if attach_to :
322
+
323
+ _ = self .attach_files_to_model_output (
324
+ attach_to , files = mu .get_uploaded_file_ids (response )
325
+ )
326
+
312
327
return response
313
328
314
329
def list_files (self , id : str ) -> Union [dict , requests .Response ]:
0 commit comments