[Cleanup] Use mkstemp (#21676)

`tempfile.mktemp` is technically deprecated in favor of `tempfile.mkstemp`. 
Ref: https://docs.python.org/3/library/tempfile.html#deprecated-functions-and-variables.
This commit is contained in:
Ian Rodney 2022-01-25 13:42:12 -08:00 committed by GitHub
parent e4370720cc
commit 257bd2d1e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 10 deletions

View file

@ -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)

View file

@ -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 = [

View file

@ -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:

View file

@ -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)

View file

@ -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",

View file

@ -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)