summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-04-02 11:28:49 -0400
committerBenjamin Peterson <benjamin@python.org>2012-04-02 11:28:49 -0400
commitdba1b40b6064107d63f228fe67a258dd1123b189 (patch)
treea6ebdf8a8504bb769e622ffb7a5cc85aa2a49652
parent38548ad006ee5df07a680ee06d88e8509cdbe3ea (diff)
parente900096dc42cd0d590752e00ba3983b4672da806 (diff)
downloadcpython-git-dba1b40b6064107d63f228fe67a258dd1123b189.tar.gz
merge 3.2
-rw-r--r--Lib/test/test_thread.py24
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_threadmodule.c3
3 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py
index 894a49392e..deb4bf3620 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -128,6 +128,30 @@ class ThreadRunningTests(BasicThreadTest):
time.sleep(0.01)
self.assertEqual(thread._count(), orig)
+ def test_save_exception_state_on_error(self):
+ # See issue #14474
+ def task():
+ started.release()
+ sys.stderr = stderr
+ raise SyntaxError
+ def mywrite(self, *args):
+ try:
+ raise ValueError
+ except ValueError:
+ pass
+ real_write(self, *args)
+ c = thread._count()
+ started = thread.allocate_lock()
+ with support.captured_output("stderr") as stderr:
+ real_write = stderr.write
+ stderr.write = mywrite
+ started.acquire()
+ thread.start_new_thread(task, ())
+ started.acquire()
+ while thread._count() > c:
+ pass
+ self.assertIn("Traceback", stderr.getvalue())
+
class Barrier:
def __init__(self, num_threads):
diff --git a/Misc/NEWS b/Misc/NEWS
index b38f104a81..8f66178346 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.3.0 Alpha 3?
Core and Builtins
-----------------
+- Issue #14474: Save and restore exception state in thread.start_new_thread()
+ while writing error message if the thread leaves a unhandled exception.
+
- Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch
by Suman Saha.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 6e39ca047e..8f66cb37e0 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -1001,14 +1001,17 @@ t_bootstrap(void *boot_raw)
PyErr_Clear();
else {
PyObject *file;
+ PyObject *exc, *value, *tb;
PySys_WriteStderr(
"Unhandled exception in thread started by ");
+ PyErr_Fetch(&exc, &value, &tb);
file = PySys_GetObject("stderr");
if (file != NULL && file != Py_None)
PyFile_WriteObject(boot->func, file, 0);
else
PyObject_Print(boot->func, stderr, 0);
PySys_WriteStderr("\n");
+ PyErr_Restore(exc, value, tb);
PyErr_PrintEx(0);
}
}