summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-04-30 16:51:39 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2020-04-30 16:51:39 +0200
commit72e65b4319f34426e7b43c2b70c4c31fee8024bb (patch)
tree80ce9a17e46fd49928622bd32d3a3ac86d350037
parent6514a70318688a119405b83dbd4e3b8da45c3ee9 (diff)
downloadpsutil-72e65b4319f34426e7b43c2b70c4c31fee8024bb.tar.gz
rm get_testfn()
-rw-r--r--psutil/tests/__init__.py49
1 files changed, 26 insertions, 23 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index 8db01587..6f614ccf 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -336,29 +336,32 @@ def create_proc_children_pair():
and are registered for cleanup on reap_children().
"""
# must be relative on Windows
- testfn = os.path.basename(get_testfn(dir=os.getcwd()))
- s = textwrap.dedent("""\
- import subprocess, os, sys, time
- s = "import os, time;"
- s += "f = open('%s', 'w');"
- s += "f.write(str(os.getpid()));"
- s += "f.close();"
- s += "time.sleep(60);"
- p = subprocess.Popen([r'%s', '-c', s])
- p.wait()
- """ % (testfn, PYTHON_EXE))
- # On Windows if we create a subprocess with CREATE_NO_WINDOW flag
- # set (which is the default) a "conhost.exe" extra process will be
- # spawned as a child. We don't want that.
- if WINDOWS:
- subp = pyrun(s, creationflags=0)
- else:
- subp = pyrun(s)
- child = psutil.Process(subp.pid)
- grandchild_pid = int(wait_for_file(testfn, delete=True, empty=False))
- _pids_started.add(grandchild_pid)
- grandchild = psutil.Process(grandchild_pid)
- return (child, grandchild)
+ testfn = get_testfn(dir=os.getcwd())
+ try:
+ s = textwrap.dedent("""\
+ import subprocess, os, sys, time
+ s = "import os, time;"
+ s += "f = open('%s', 'w');"
+ s += "f.write(str(os.getpid()));"
+ s += "f.close();"
+ s += "time.sleep(60);"
+ p = subprocess.Popen([r'%s', '-c', s])
+ p.wait()
+ """ % (os.path.basename(testfn), PYTHON_EXE))
+ # On Windows if we create a subprocess with CREATE_NO_WINDOW flag
+ # set (which is the default) a "conhost.exe" extra process will be
+ # spawned as a child. We don't want that.
+ if WINDOWS:
+ subp = pyrun(s, creationflags=0)
+ else:
+ subp = pyrun(s)
+ child = psutil.Process(subp.pid)
+ grandchild_pid = int(wait_for_file(testfn, delete=True, empty=False))
+ _pids_started.add(grandchild_pid)
+ grandchild = psutil.Process(grandchild_pid)
+ return (child, grandchild)
+ finally:
+ safe_rmpath(testfn)
def create_zombie_proc():