From d6da7604d3eb19635f27e3d2d66e5a973cc26266 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D)" Date: Fri, 3 Jun 2016 06:14:06 +0000 Subject: Issue #27167: Clarify the subprocess.CalledProcessError error message text when the child process died due to a signal. --- Lib/subprocess.py | 19 +++++++++++++++---- Lib/test/test_subprocess.py | 19 +++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index b853f4d..716f7ff 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -372,9 +372,11 @@ class SubprocessError(Exception): pass class CalledProcessError(SubprocessError): - """This exception is raised when a process run by check_call() or - check_output() returns a non-zero exit status. - The exit status will be stored in the returncode attribute; + """Raised when a check_call() or check_output() process returns non-zero. + + The exit status will be stored in the returncode attribute, negative + if it represents a signal number. + check_output() will also store the output in the output attribute. """ def __init__(self, returncode, cmd, output=None, stderr=None): @@ -384,7 +386,16 @@ class CalledProcessError(SubprocessError): self.stderr = stderr def __str__(self): - return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode) + if self.returncode and self.returncode < 0: + try: + return "Command '%s' died with %r." % ( + self.cmd, signal.Signals(-self.returncode)) + except ValueError: + return "Command '%s' died with unknown signal %d." % ( + self.cmd, -self.returncode) + else: + return "Command '%s' returned non-zero exit status %d." % ( + self.cmd, self.returncode) @property def stdout(self): diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index a8f0a64..8a2352b 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1427,6 +1427,25 @@ class POSIXProcessTestCase(BaseTestCase): p.wait() self.assertEqual(-p.returncode, signal.SIGABRT) + def test_CalledProcessError_str_signal(self): + err = subprocess.CalledProcessError(-int(signal.SIGABRT), "fake cmd") + error_string = str(err) + # We're relying on the repr() of the signal.Signals intenum to provide + # the word signal, the signal name and the numeric value. + self.assertIn("signal", error_string.lower()) + self.assertIn("SIGABRT", error_string) + self.assertIn(str(signal.SIGABRT), error_string) + + def test_CalledProcessError_str_unknown_signal(self): + err = subprocess.CalledProcessError(-9876543, "fake cmd") + error_string = str(err) + self.assertIn("unknown signal 9876543.", error_string) + + def test_CalledProcessError_str_non_zero(self): + err = subprocess.CalledProcessError(2, "fake cmd") + error_string = str(err) + self.assertIn("non-zero exit status 2.", error_string) + def test_preexec(self): # DISCLAIMER: Setting environment variables is *not* a good use # of a preexec_fn. This is merely a test. diff --git a/Misc/NEWS b/Misc/NEWS index 4220062..57edb49 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -22,6 +22,9 @@ Core and Builtins Library ------- +- Issue #27167: Clarify the subprocess.CalledProcessError error message text + when the child process died due to a signal. + - Issue #25931: Don't define socketserver.Forking* names on platforms such as Windows that do not support os.fork(). -- cgit v0.12 From b414906f9399fc3ca60abab9e7f0dba5ba4c4b30 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D)" Date: Fri, 3 Jun 2016 06:19:35 +0000 Subject: issue27167: make the test not care about the exact signal name in the error message as some numbers map to multiple names. --- Lib/test/test_subprocess.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 8a2352b..cb0e292 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1433,7 +1433,9 @@ class POSIXProcessTestCase(BaseTestCase): # We're relying on the repr() of the signal.Signals intenum to provide # the word signal, the signal name and the numeric value. self.assertIn("signal", error_string.lower()) - self.assertIn("SIGABRT", error_string) + # We're not being specific about the signal name as some signals have + # multiple names and which name is revealed can vary. + self.assertIn("SIG", error_string) self.assertIn(str(signal.SIGABRT), error_string) def test_CalledProcessError_str_unknown_signal(self): -- cgit v0.12 From 0779129302655b11d66f6f3479d9f881cccd16e2 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Thu, 2 Jun 2016 23:49:05 -0700 Subject: issue8519 - Reference termios and ioctl manual pages in the library documentation. --- Doc/library/fcntl.rst | 4 +++- Doc/library/termios.rst | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst index 22f0f25..508c4a5 100644 --- a/Doc/library/fcntl.rst +++ b/Doc/library/fcntl.rst @@ -12,7 +12,9 @@ pair: UNIX; I/O control This module performs file control and I/O control on file descriptors. It is an -interface to the :c:func:`fcntl` and :c:func:`ioctl` Unix routines. +interface to the :c:func:`fcntl` and :c:func:`ioctl` Unix routines. For a +complete description of these calls, see :manpage:`fcntl(2)` and +:manpage:`ioctl(2)` Unix manual pages. All functions in this module take a file descriptor *fd* as their first argument. This can be an integer file descriptor, such as returned by diff --git a/Doc/library/termios.rst b/Doc/library/termios.rst index a90a825..d225d94 100644 --- a/Doc/library/termios.rst +++ b/Doc/library/termios.rst @@ -10,10 +10,10 @@ pair: POSIX; I/O control pair: tty; I/O control -This module provides an interface to the POSIX calls for tty I/O control. For a -complete description of these calls, see the POSIX or Unix manual pages. It is -only available for those Unix versions that support POSIX *termios* style tty -I/O control (and then only if configured at installation time). +This module provides an interface to the POSIX calls for tty I/O control. For a +complete description of these calls, see :manpage:`termios(2)` Unix manual +page. It is only available for those Unix versions that support POSIX +*termios* style tty I/O control configured during installation. All functions in this module take a file descriptor *fd* as their first argument. This can be an integer file descriptor, such as returned by -- cgit v0.12 From 7ee91942b4c68d0d0ca9db9aace40d4bc918195b Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Fri, 3 Jun 2016 00:03:48 -0700 Subject: issue27113 - Document "check_same_thread" parameter in sqlite3.connect api. Patch contributed by Dave Sawyer. --- Doc/library/sqlite3.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst index f6e5384..996e93e 100644 --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -190,6 +190,11 @@ Module functions and constants any combination of :const:`PARSE_DECLTYPES` and :const:`PARSE_COLNAMES` to turn type detection on. + By default, *check_same_thread* is :const:`True` and only the creating thread may + use the connection. If set :const:`False`, the returned connection may be shared + across multiple threads. When using multiple threads with the same connection + writing operations should be serialized by the user to avoid data corruption. + By default, the :mod:`sqlite3` module uses its :class:`Connection` class for the connect call. You can, however, subclass the :class:`Connection` class and make :func:`connect` use your class instead by providing your class for the *factory* -- cgit v0.12