Skip to content

Commit

Permalink
Replaced use of tempfile.mktemp() with tempfile.mkstemp() (#3358)
Browse files Browse the repository at this point in the history
Signed-off-by: Abin Shahab <ashahab@linkedin.com>
  • Loading branch information
ashahab committed Jan 16, 2022
1 parent 655353f commit b96ecae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 6 additions & 1 deletion horovod/runner/js_run.py
Expand Up @@ -126,7 +126,12 @@ def generate_jsrun_rankfile(settings, path=None):
slots=settings.num_proc))

# Generate rankfile
path = tempfile.mktemp() if path is None else path
# using mkstemp here instead of insecure mktemp.
# note that the caller is responsible for cleaning up this file
if path is None:
fd, path = tempfile.mkstemp()
fd.close()

with open(path, 'w') as tmp:
tmp.write('overlapping_rs: allow\n')
tmp.write('cpu_index_using: logical\n')
Expand Down
2 changes: 1 addition & 1 deletion test/single/test_run.py
Expand Up @@ -640,7 +640,7 @@ def test(output, expected, exit_code=0):
test(("HYDRA build details:\n"
" Version: 3.3a2\n"
" Configure options: 'MPICHLIB_CFLAGS=-g -O2'\n"), _MPICH_IMPL)

test("Intel(R) MPI", _IMPI_IMPL)

test("Unknown MPI v1.00", _UNKNOWN_IMPL)
Expand Down
9 changes: 3 additions & 6 deletions test/utils/common.py
Expand Up @@ -112,15 +112,12 @@ def tempdir():

@contextlib.contextmanager
def temppath():
path = tempfile.mktemp()
dir_path = tempfile.TemporaryDirectory()
path = os.path.join(dir_path.name,'temp_test_file')
try:
yield path
finally:
if os.path.exists(path):
if os.path.isfile(path):
os.remove(path)
else:
shutil.rmtree(path)
dir_path.cleanup()


@contextlib.contextmanager
Expand Down

0 comments on commit b96ecae

Please sign in to comment.