]> granicus.if.org Git - python/commitdiff
Add a test for same-thread asynchronous exceptions (see #1779233).
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 18 Oct 2009 18:22:04 +0000 (18:22 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 18 Oct 2009 18:22:04 +0000 (18:22 +0000)
Lib/test/test_threading.py

index 233ccf65c93724f327c583b10647cb08cb163c77..5f4b0261bfa95cfa31ed39b75a79b1b3c312b29a 100644 (file)
@@ -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