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

Skip to content

Commit 964561b

Browse files
committed
you can't get resource.error if you can't import resource
1 parent 13859bf commit 964561b

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
#
@@ -732,12 +738,12 @@ class _SuppressCoreFiles(object):
732738

733739
def __enter__(self):
734740
"""Try to save previous ulimit, then set it to (0, 0)."""
735-
try:
736-
import resource
737-
self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
738-
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
739-
except (ImportError, ValueError, resource.error):
740-
pass
741+
if resource is not None:
742+
try:
743+
self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
744+
resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
745+
except (ValueError, resource.error):
746+
pass
741747

742748
if sys.platform == 'darwin':
743749
# Check if the 'Crash Reporter' on OSX was configured
@@ -758,11 +764,11 @@ def __exit__(self, *args):
758764
"""Return core file behavior to default."""
759765
if self.old_limit is None:
760766
return
761-
try:
762-
import resource
763-
resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
764-
except (ImportError, ValueError, resource.error):
765-
pass
767+
if resource is not None:
768+
try:
769+
resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
770+
except (ValueError, resource.error):
771+
pass
766772

767773

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

0 commit comments

Comments
 (0)