File size: 1,798 Bytes
8247f19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
diff --git a/horovod/runner/js_run.py b/horovod/runner/js_run.py
index d25f5dd3..5be68011 100644
--- a/horovod/runner/js_run.py
+++ b/horovod/runner/js_run.py
@@ -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')
diff --git a/test/single/test_run.py b/test/single/test_run.py
index f7a82cd0..5f506f9f 100644
--- a/test/single/test_run.py
+++ b/test/single/test_run.py
@@ -640,7 +640,7 @@ class RunTests(unittest.TestCase):
         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)
diff --git a/test/utils/common.py b/test/utils/common.py
index 038ed1ea..77871c45 100644
--- a/test/utils/common.py
+++ b/test/utils/common.py
@@ -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