[Python-checkins] cpython (3.2): you can't get resource.error if you can't import resource

benjamin.peterson python-checkins at python.org
Sat Dec 10 18:39:29 CET 2011


http://hg.python.org/cpython/rev/245f6094ccba
changeset:   73923:245f6094ccba
branch:      3.2
parent:      73919:c998c6f5464b
user:        Benjamin Peterson <benjamin at python.org>
date:        Sat Dec 10 12:31:42 2011 -0500
summary:
  you can't get resource.error if you can't import resource

files:
  Lib/test/test_subprocess.py |  28 +++++++++++++++---------
  1 files changed, 17 insertions(+), 11 deletions(-)


diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -18,6 +18,12 @@
 except ImportError:
     gc = None
 
+
+try:
+    import resource
+except ImportError:
+    resource = None
+
 mswindows = (sys.platform == "win32")
 
 #
@@ -732,12 +738,12 @@
 
     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
@@ -758,11 +764,11 @@
         """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.skipIf(mswindows, "POSIX specific tests")

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list