summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2010-04-25 22:33:36 (GMT)
committerBrett Cannon <bcannon@gmail.com>2010-04-25 22:33:36 (GMT)
commit1994969c15a055d2f9479d3bc10fb6304b2979ed (patch)
tree2a3cf51468cd824600a531482ff11e04fbdd29a7 /Lib
parenta624040d72b7a83bab4737fdfe14b747b530f858 (diff)
downloadcpython-1994969c15a055d2f9479d3bc10fb6304b2979ed.zip
cpython-1994969c15a055d2f9479d3bc10fb6304b2979ed.tar.gz
cpython-1994969c15a055d2f9479d3bc10fb6304b2979ed.tar.bz2
When DeprecationWarning was silenced by default, it also silenced any use of -Q
by default as well. This change fixes that by treating -Q like -3 when it comes to DeprecationWarning; using it causes the silencing to not occur. Fixes issue #7319.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/subprocess.py53
-rw-r--r--Lib/warnings.py3
2 files changed, 38 insertions, 18 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 8c687c9..3cd2357 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -413,7 +413,6 @@ class CalledProcessError(Exception):
if mswindows:
- from _subprocess import CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP
import threading
import msvcrt
import _subprocess
@@ -442,6 +441,7 @@ __all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call",
"check_output", "CalledProcessError"]
if mswindows:
+ from _subprocess import CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP
__all__.extend(["CREATE_NEW_CONSOLE", "CREATE_NEW_PROCESS_GROUP"])
try:
MAXFD = os.sysconf("SC_OPEN_MAX")
@@ -699,12 +699,12 @@ class Popen(object):
return data
- def __del__(self, sys=sys):
+ def __del__(self, _maxint=sys.maxint):
if not self._child_created:
# We didn't get to successfully create a child process.
return
# In case the child hasn't been waited on, check if it's done.
- self._internal_poll(_deadstate=sys.maxint)
+ self._internal_poll(_deadstate=_maxint)
if self.returncode is None and _active is not None:
# Child is still running, keep us alive until we can wait on it.
_active.append(self)
@@ -907,13 +907,20 @@ class Popen(object):
errwrite.Close()
- def _internal_poll(self, _deadstate=None):
+ def _internal_poll(self, _deadstate=None,
+ _WaitForSingleObject=WaitForSingleObject,
+ _WAIT_OBJECT_0=WAIT_OBJECT_0,
+ _GetExitCodeProcess=GetExitCodeProcess):
"""Check if child process has terminated. Returns returncode
- attribute."""
+ attribute.
+
+ This method is called by __del__, so it can only refer to objects
+ in its local scope.
+
+ """
if self.returncode is None:
- if(_subprocess.WaitForSingleObject(self._handle, 0) ==
- _subprocess.WAIT_OBJECT_0):
- self.returncode = _subprocess.GetExitCodeProcess(self._handle)
+ if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
+ self.returncode = _GetExitCodeProcess(self._handle)
return self.returncode
@@ -1194,25 +1201,37 @@ class Popen(object):
raise child_exception
- def _handle_exitstatus(self, sts):
- if os.WIFSIGNALED(sts):
- self.returncode = -os.WTERMSIG(sts)
- elif os.WIFEXITED(sts):
- self.returncode = os.WEXITSTATUS(sts)
+ def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
+ _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
+ _WEXITSTATUS=os.WEXITSTATUS):
+ """
+
+ This method is called (indirectly) by __del__, so it cannot
+ refer to anything outside of its local scope."""
+ if _WIFSIGNALED(sts):
+ self.returncode = -_WTERMSIG(sts)
+ elif _WIFEXITED(sts):
+ self.returncode = _WEXITSTATUS(sts)
else:
# Should never happen
raise RuntimeError("Unknown child exit status!")
- def _internal_poll(self, _deadstate=None):
+ def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid,
+ _WNOHANG=os.WNOHANG, _os_error=os.error):
"""Check if child process has terminated. Returns returncode
- attribute."""
+ attribute.
+
+ This method is called by __del__, so it cannot reference anything
+ outside of the local scope (nor can any methods it calls).
+
+ """
if self.returncode is None:
try:
- pid, sts = os.waitpid(self.pid, os.WNOHANG)
+ pid, sts = _waitpid(self.pid, _WNOHANG)
if pid == self.pid:
self._handle_exitstatus(sts)
- except os.error:
+ except _os_error:
if _deadstate is not None:
self.returncode = _deadstate
return self.returncode
diff --git a/Lib/warnings.py b/Lib/warnings.py
index 134ba13..08b70af 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -384,7 +384,8 @@ except ImportError:
_processoptions(sys.warnoptions)
if not _warnings_defaults:
silence = [ImportWarning, PendingDeprecationWarning]
- if not sys.py3kwarning: # Don't silence DeprecationWarning if -3 was used.
+ # Don't silence DeprecationWarning if -3 or -Q was used.
+ if not sys.py3kwarning and not sys.flags.division_warning:
silence.append(DeprecationWarning)
for cls in silence:
simplefilter("ignore", category=cls)