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

Skip to content

Commit eec9331

Browse files
committed
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.
1 parent 54005af commit eec9331

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lib/test/test_threading.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,24 @@ def run():
10431043
self.assertEqual(out, b'')
10441044
self.assertNotIn("Unhandled exception", err.decode())
10451045

1046+
def test_bare_raise_in_brand_new_thread(self):
1047+
def bare_raise():
1048+
raise
1049+
1050+
class Issue27558(threading.Thread):
1051+
exc = None
1052+
1053+
def run(self):
1054+
try:
1055+
bare_raise()
1056+
except Exception as exc:
1057+
self.exc = exc
1058+
1059+
thread = Issue27558()
1060+
thread.start()
1061+
thread.join()
1062+
self.assertIsNotNone(thread.exc)
1063+
self.assertIsInstance(thread.exc, RuntimeError)
10461064

10471065
class TimerTests(BaseTestCase):
10481066

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27558: Fix a SystemError in the implementation of "raise" statement.
14+
In a brand new thread, raise a RuntimeError since there is no active
15+
exception to reraise. Patch written by Xiang Zhang.
16+
1317
- Issue #27419: Standard __import__() no longer look up "__import__" in globals
1418
or builtins for importing submodules or "from import". Fixed handling an
1519
error of non-string package name.

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4123,7 +4123,7 @@ do_raise(PyObject *exc, PyObject *cause)
41234123
type = tstate->exc_type;
41244124
value = tstate->exc_value;
41254125
tb = tstate->exc_traceback;
4126-
if (type == Py_None) {
4126+
if (type == Py_None || type == NULL) {
41274127
PyErr_SetString(PyExc_RuntimeError,
41284128
"No active exception to reraise");
41294129
return 0;

0 commit comments

Comments
 (0)