summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-12-10 17:31:42 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-12-10 17:31:42 (GMT)
commit8b59c23a54a053673c07c6939cccef096d856103 (patch)
tree41c3c8cdd2db97690be9f77cff5c51323a28aff9 /Lib
parent97c9428c9105048fb062ac97f5542294692ab701 (diff)
downloadcpython-8b59c23a54a053673c07c6939cccef096d856103.zip
cpython-8b59c23a54a053673c07c6939cccef096d856103.tar.gz
cpython-8b59c23a54a053673c07c6939cccef096d856103.tar.bz2
you can't get resource.error if you can't import resource
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_subprocess.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 1aa2c0a..b66356d 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -10,6 +10,11 @@ import time
import re
import sysconfig
+try:
+ import resource
+except ImportError:
+ resource = None
+
mswindows = (sys.platform == "win32")
#
@@ -633,12 +638,12 @@ class _SuppressCoreFiles(object):
def __enter__(self):
"""Try to save previous ulimit, then set it to (0, 0)."""
- try:
- import resource
- self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
- resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
- except (ImportError, ValueError, resource.error):
- pass
+ if resource is not None:
+ try:
+ self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
+ resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
+ except (ValueError, resource.error):
+ pass
if sys.platform == 'darwin':
# Check if the 'Crash Reporter' on OSX was configured
@@ -658,11 +663,11 @@ class _SuppressCoreFiles(object):
"""Return core file behavior to default."""
if self.old_limit is None:
return
- try:
- import resource
- resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
- except (ImportError, ValueError, resource.error):
- pass
+ if resource is not None:
+ try:
+ resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
+ except (ValueError, resource.error):
+ pass
@unittest.skipUnless(hasattr(signal, 'SIGALRM'),
"Requires signal.SIGALRM")