From 61984e6843d2e59235d82a580c529920cd8f3711 Mon Sep 17 00:00:00 2001 From: Corey Zumar <39497902+dbczumar@users.noreply.github.com> Date: Wed, 26 Jan 2022 15:59:23 -0800 Subject: [PATCH] Use mkstemp to replace deprecated mktemp call (#5303) * Use mkstemp Signed-off-by: dbczumar * Remove num examples Signed-off-by: dbczumar * Close instead of remove Signed-off-by: dbczumar * Close the handle Signed-off-by: dbczumar --- mlflow/utils/file_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlflow/utils/file_utils.py b/mlflow/utils/file_utils.py index 32653b343c445..4b59a367372af 100644 --- a/mlflow/utils/file_utils.py +++ b/mlflow/utils/file_utils.py @@ -287,7 +287,7 @@ def _filter_timestamps(tar_info): tar_info.mtime = 0 return tar_info if custom_filter is None else custom_filter(tar_info) - unzipped_filename = tempfile.mktemp() + unzipped_file_handle, unzipped_filename = tempfile.mkstemp() try: with tarfile.open(unzipped_filename, "w") as tar: tar.add(source_dir, arcname=archive_name, filter=_filter_timestamps) @@ -298,7 +298,7 @@ def _filter_timestamps(tar_info): ) as gzipped_tar, open(unzipped_filename, "rb") as tar: gzipped_tar.write(tar.read()) finally: - os.remove(unzipped_filename) + os.close(unzipped_file_handle) def _copy_project(src_path, dst_path=""):