Skip to content

Commit

Permalink
Merge pull request #21 from AIAScience/ij/improve-put-dataset
Browse files Browse the repository at this point in the history
Improve put_dataset
  • Loading branch information
meklitAIA committed Sep 16, 2019
2 parents 6d0bac4 + 890b142 commit 011ec50
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mflux_ai/mflux_ai.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import io
import os
import tempfile

Expand Down Expand Up @@ -142,14 +143,16 @@ def put_dataset(value, object_name, bucket_name="datasets"):
"""
minio_client = get_minio_client()

tmp_file_path = os.path.join(tempfile.gettempdir(), object_name)
joblib.dump(value, tmp_file_path, compress=True)
in_memory_file = io.BytesIO()
joblib.dump(value, in_memory_file, compress=True)
num_bytes = in_memory_file.getbuffer().nbytes

# Prepare for the read() call on the in-memory file object
in_memory_file.seek(0)

for _ in range(2):
try:
minio_client.fput_object(
bucket_name, object_name=object_name, file_path=tmp_file_path
)
minio_client.put_object(bucket_name, object_name, in_memory_file, num_bytes)
break # Success! Now exit the loop
except ResponseError as err:
print(err)
Expand Down

0 comments on commit 011ec50

Please sign in to comment.