Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3a345a

Browse files
committed
merge 3.2
2 parents 10a6ddb + 964561b commit d3a345a

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
except ImportError:
1919
gc = None
2020

21+
22+
try:
23+
import resource
24+
except ImportError:
25+
resource = None
26+
2127
mswindows = (sys.platform == "win32")
2228

2329
#
@@ -824,12 +830,12 @@ class _SuppressCoreFiles(object):
824830

825831
def __enter__(self):
826832
"""Try to save previous ulimit, then set it to (0, 0)."""
827-
try:
828-
import resource
829-
self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
830-
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
831-
except (ImportError, ValueError, resource.error):
832-
pass
833+
if resource is not None:
834+
try:
835+
self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
836+
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
837+
except (ValueError, resource.error):
838+
pass
833839

834840
if sys.platform == 'darwin':
835841
# Check if the 'Crash Reporter' on OSX was configured
@@ -850,11 +856,11 @@ def __exit__(self, *args):
850856
"""Return core file behavior to default."""
851857
if self.old_limit is None:
852858
return
853-
try:
854-
import resource
855-
resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
856-
except (ImportError, ValueError, resource.error):
857-
pass
859+
if resource is not None:
860+
try:
861+
resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
862+
except (ValueError, resource.error):
863+
pass
858864

859865

860866
@unittest.skipIf(mswindows, "POSIX specific tests")

0 commit comments

Comments
 (0)