diff --git a/python/ray/autoscaler/_private/cluster_dump.py b/python/ray/autoscaler/_private/cluster_dump.py index bb7ef0f23..c4411d0b6 100644 --- a/python/ray/autoscaler/_private/cluster_dump.py +++ b/python/ray/autoscaler/_private/cluster_dump.py @@ -84,8 +84,8 @@ class Archive: """ def __init__(self, file: Optional[str] = None): - self.file = file or tempfile.mktemp( - prefix="ray_logs_", suffix=".tar.gz") + self.file = file or tempfile.mkstemp( + prefix="ray_logs_", suffix=".tar.gz")[1] self.tar = None self._lock = threading.Lock() @@ -409,8 +409,8 @@ def create_and_get_archive_from_remote_node(remote_node: Node, cat = "node" if not remote_node.is_head else "head" cli_logger.print(f"Collecting data from remote node: {remote_node.host}") - tmp = tempfile.mktemp( - prefix=f"ray_{cat}_{remote_node.host}_", suffix=".tar.gz") + tmp = tempfile.mkstemp( + prefix=f"ray_{cat}_{remote_node.host}_", suffix=".tar.gz")[1] with open(tmp, "wb") as fp: try: subprocess.check_call(cmd, stdout=fp, stderr=sys.stderr) diff --git a/python/ray/cluster_utils.py b/python/ray/cluster_utils.py index ce8e2c2c8..baf248b96 100644 --- a/python/ray/cluster_utils.py +++ b/python/ray/cluster_utils.py @@ -62,7 +62,7 @@ class AutoscalingCluster: ray.init("auto"). """ subprocess.check_call(["ray", "stop", "--force"]) - fake_config = tempfile.mktemp() + _, fake_config = tempfile.mkstemp() with open(fake_config, "w") as f: f.write(json.dumps(self._config)) cmd = [ diff --git a/python/ray/serve/tests/test_fastapi.py b/python/ray/serve/tests/test_fastapi.py index b6fbc6ddc..87472804d 100644 --- a/python/ray/serve/tests/test_fastapi.py +++ b/python/ray/serve/tests/test_fastapi.py @@ -172,7 +172,7 @@ def test_fastapi_features(serve_instance): }) def run_background(background_tasks: BackgroundTasks): - path = tempfile.mktemp() + _, path = tempfile.mkstemp() def write_to_file(p): with open(p, "w") as f: diff --git a/python/ray/tune/tests/test_checkpoint_manager.py b/python/ray/tune/tests/test_checkpoint_manager.py index 216341f12..3b577083f 100644 --- a/python/ray/tune/tests/test_checkpoint_manager.py +++ b/python/ray/tune/tests/test_checkpoint_manager.py @@ -136,7 +136,7 @@ class CheckpointManagerTest(unittest.TestCase): tmpfiles = [] for i in range(3): - tmpfile = tempfile.mktemp() + _, tmpfile = tempfile.mkstemp() with open(tmpfile, "wt") as fp: fp.write("") tmpfiles.append(tmpfile) diff --git a/python/ray/tune/tests/test_trial_scheduler.py b/python/ray/tune/tests/test_trial_scheduler.py index 49cd2183d..7fafd041c 100644 --- a/python/ray/tune/tests/test_trial_scheduler.py +++ b/python/ray/tune/tests/test_trial_scheduler.py @@ -2091,7 +2091,7 @@ class AsyncHyperBandSuite(unittest.TestCase): TrialScheduler.STOP) def testAsyncHBSaveRestore(self): - tmpfile = tempfile.mktemp() + _, tmpfile = tempfile.mkstemp() scheduler = AsyncHyperBandScheduler( metric="episode_reward_mean", diff --git a/release/tune_tests/cloud_tests/workloads/run_cloud_test.py b/release/tune_tests/cloud_tests/workloads/run_cloud_test.py index 7ecc7cede..15a2a6a6c 100644 --- a/release/tune_tests/cloud_tests/workloads/run_cloud_test.py +++ b/release/tune_tests/cloud_tests/workloads/run_cloud_test.py @@ -389,7 +389,7 @@ def fetch_remote_directory_content( local_dir: str, ): def _pack(dir: str): - tmpfile = tempfile.mktemp() + _, tmpfile = tempfile.mkstemp() with tarfile.open(tmpfile, "w:gz") as tar: tar.add(dir, arcname="") @@ -399,7 +399,7 @@ def fetch_remote_directory_content( return stream def _unpack(stream: str, dir: str): - tmpfile = tempfile.mktemp() + _, tmpfile = tempfile.mkstemp() with open(tmpfile, "wb") as f: f.write(stream)