changeset: 102740:ba45fbb16499 branch: 3.5 parent: 102733:df3a907d94cd user: Victor Stinner date: Thu Aug 18 18:13:10 2016 +0200 files: Lib/test/test_threading.py Misc/NEWS Python/ceval.c description: Fix SystemError in "raise" statement Issue #27558: Fix a SystemError in the implementation of "raise" statement. In a brand new thread, raise a RuntimeError since there is no active exception to reraise. Patch written by Xiang Zhang. diff -r df3a907d94cd -r ba45fbb16499 Lib/test/test_threading.py --- a/Lib/test/test_threading.py Wed Aug 17 09:51:20 2016 -0500 +++ b/Lib/test/test_threading.py Thu Aug 18 18:13:10 2016 +0200 @@ -1043,6 +1043,24 @@ self.assertEqual(out, b'') self.assertNotIn("Unhandled exception", err.decode()) + def test_bare_raise_in_brand_new_thread(self): + def bare_raise(): + raise + + class Issue27558(threading.Thread): + exc = None + + def run(self): + try: + bare_raise() + except Exception as exc: + self.exc = exc + + thread = Issue27558() + thread.start() + thread.join() + self.assertIsNotNone(thread.exc) + self.assertIsInstance(thread.exc, RuntimeError) class TimerTests(BaseTestCase): diff -r df3a907d94cd -r ba45fbb16499 Misc/NEWS --- a/Misc/NEWS Wed Aug 17 09:51:20 2016 -0500 +++ b/Misc/NEWS Thu Aug 18 18:13:10 2016 +0200 @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #27558: Fix a SystemError in the implementation of "raise" statement. + In a brand new thread, raise a RuntimeError since there is no active + exception to reraise. Patch written by Xiang Zhang. + - Issue #27419: Standard __import__() no longer look up "__import__" in globals or builtins for importing submodules or "from import". Fixed handling an error of non-string package name. diff -r df3a907d94cd -r ba45fbb16499 Python/ceval.c --- a/Python/ceval.c Wed Aug 17 09:51:20 2016 -0500 +++ b/Python/ceval.c Thu Aug 18 18:13:10 2016 +0200 @@ -4123,7 +4123,7 @@ type = tstate->exc_type; value = tstate->exc_value; tb = tstate->exc_traceback; - if (type == Py_None) { + if (type == Py_None || type == NULL) { PyErr_SetString(PyExc_RuntimeError, "No active exception to reraise"); return 0;