summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-10-18 18:22:04 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-10-18 18:22:04 (GMT)
commit8a172b14a3a87e4c03c7689cdb6becbbe1badcb8 (patch)
tree4504f272cea65bf665c019f40e42f395eb93ccec
parent53a9dc91d7aaa460cf4899b81dbbfd48b9fe071b (diff)
downloadcpython-8a172b14a3a87e4c03c7689cdb6becbbe1badcb8.zip
cpython-8a172b14a3a87e4c03c7689cdb6becbbe1badcb8.tar.gz
cpython-8a172b14a3a87e4c03c7689cdb6becbbe1badcb8.tar.bz2
Add a test for same-thread asynchronous exceptions (see #1779233).
-rw-r--r--Lib/test/test_threading.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 233ccf6..5f4b026 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -164,6 +164,25 @@ class ThreadTests(unittest.TestCase):
exception = ctypes.py_object(AsyncExc)
+ # First check it works when setting the exception from the same thread.
+ tid = thread.get_ident()
+
+ try:
+ result = set_async_exc(ctypes.c_long(tid), exception)
+ # The exception is async, so we might have to keep the VM busy until
+ # it notices.
+ while True:
+ pass
+ except AsyncExc:
+ pass
+ else:
+ self.fail("AsyncExc not raised")
+ try:
+ self.assertEqual(result, 1) # one thread state modified
+ except UnboundLocalError:
+ # The exception was raised to quickly for us to get the result.
+ pass
+
# `worker_started` is set by the thread when it's inside a try/except
# block waiting to catch the asynchronously set AsyncExc exception.
# `worker_saw_exception` is set by the thread upon catching that