From d723299f1eac75ccb87b21ad802a9683761d3bd5 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Thu, 22 Dec 2022 21:48:07 +0200 Subject: [PATCH] Fix can't write more than 2 GB to a file --- clearml/binding/artifacts.py | 4 ++-- clearml/binding/frameworks/tensorflow_bind.py | 11 ++++------- clearml/binding/matplotlib_bind.py | 5 ++--- clearml/task.py | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/clearml/binding/artifacts.py b/clearml/binding/artifacts.py index e891be8a..64b67708 100644 --- a/clearml/binding/artifacts.py +++ b/clearml/binding/artifacts.py @@ -562,8 +562,8 @@ class Artifacts(object): if serialized_text is not None: override_filename_in_uri = name + override_filename_ext_in_uri fd, local_filename = mkstemp(prefix=quote(name, safe="") + ".", suffix=override_filename_ext_in_uri) - os.write(fd, bytes(serialized_text.encode())) - os.close(fd) + with open(fd, "w") as f: + f.write(serialized_text) preview = preview or serialized_text if len(preview) < self.max_preview_size_bytes: artifact_type_data.preview = preview diff --git a/clearml/binding/frameworks/tensorflow_bind.py b/clearml/binding/frameworks/tensorflow_bind.py index d78fb6cb..2f59150b 100644 --- a/clearml/binding/frameworks/tensorflow_bind.py +++ b/clearml/binding/frameworks/tensorflow_bind.py @@ -395,17 +395,14 @@ class EventTrainsWriter(object): suffix=guess_extension(im.get_format_mimetype()) if hasattr(im, 'get_format_mimetype') else ".{}".format(str(im.format).lower()) ) - os.write(fd, imdata) - os.close(fd) + with open(fd, "wb") as f: + f.write(imdata) return temp_file - - image = np.asarray(im) output.close() if height is not None and height > 0 and width is not None and width > 0: - # noinspection PyArgumentList - val = image.reshape(height, width, -1).astype(np.uint8) + val = np.array(im).reshape((height, width, -1)).astype(np.uint8) else: - val = image.astype(np.uint8) + val = np.array(im).astype(np.uint8) if val.ndim == 3 and val.shape[2] == 3: if self._visualization_mode == 'BGR': val = val[:, :, [2, 1, 0]] diff --git a/clearml/binding/matplotlib_bind.py b/clearml/binding/matplotlib_bind.py index e5248349..f29a21cb 100644 --- a/clearml/binding/matplotlib_bind.py +++ b/clearml/binding/matplotlib_bind.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import os import sys import threading from copy import deepcopy @@ -559,8 +558,8 @@ class PatchedMatplotlib: facecolor=None) buffer_.seek(0) fd, image = mkstemp(suffix='.' + image_format) - os.write(fd, buffer_.read()) - os.close(fd) + with open(fd, "wb") as f: + f.write(buffer_.read()) # check if we need to restore the active object if set_active and not _pylab_helpers.Gcf.get_active() and stored_figure: diff --git a/clearml/task.py b/clearml/task.py index f1421af3..c1be12dc 100644 --- a/clearml/task.py +++ b/clearml/task.py @@ -1633,8 +1633,8 @@ class Task(_Task): fd, local_filename = mkstemp(prefix='clearml_task_config_', suffix=configuration_path.suffixes[-1] if configuration_path.suffixes else '.txt') - os.write(fd, configuration_text.encode('utf-8')) - os.close(fd) + with open(fd, "w") as f: + f.write(configuration_text) if pathlib_Path: return pathlib_Path(local_filename) return Path(local_filename) if isinstance(configuration, Path) else local_filename