Kaydet (Commit) 86e1e380 authored tarafından Andrew M. Kuchling's avatar Andrew M. Kuchling

[Patch #1520905] Attempt to suppress core file created by test_subprocess.py.

Patch by Douglas Greiman.

The test_run_abort() testcase produces a core file on Unix systems,
even though the test is successful. This can be confusing or alarming
to someone who runs 'make test' and then finds that the Python
interpreter apparently crashed.
üst 11d68a6a
...@@ -476,10 +476,36 @@ class ProcessTestCase(unittest.TestCase): ...@@ -476,10 +476,36 @@ class ProcessTestCase(unittest.TestCase):
else: else:
self.fail("Expected OSError") self.fail("Expected OSError")
def _suppress_core_files(self):
"""Try to prevent core files from being created.
Returns previous ulimit if successful, else None.
"""
try:
import resource
old_limit = resource.getrlimit(resource.RLIMIT_CORE)
resource.setrlimit(resource.RLIMIT_CORE, (0,0))
return old_limit
except (ImportError, ValueError, resource.error):
return None
def _unsuppress_core_files(self, old_limit):
"""Return core file behavior to default."""
if old_limit is None:
return
try:
import resource
resource.setrlimit(resource.RLIMIT_CORE, old_limit)
except (ImportError, ValueError, resource.error):
return
def test_run_abort(self): def test_run_abort(self):
# returncode handles signal termination # returncode handles signal termination
p = subprocess.Popen([sys.executable, old_limit = self._suppress_core_files()
"-c", "import os; os.abort()"]) try:
p = subprocess.Popen([sys.executable,
"-c", "import os; os.abort()"])
finally:
self._unsuppress_core_files(old_limit)
p.wait() p.wait()
self.assertEqual(-p.returncode, signal.SIGABRT) self.assertEqual(-p.returncode, signal.SIGABRT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment