From aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 23 Mar 2017 15:48:39 +0200 Subject: bpo-6532: Make the thread id an unsigned integer. (#781) * bpo-6532: Make the thread id an unsigned integer. From C API side the type of results of PyThread_start_new_thread() and PyThread_get_thread_ident(), the id parameter of PyThreadState_SetAsyncExc(), and the thread_id field of PyThreadState changed from "long" to "unsigned long". * Restore a check in thread_get_ident(). --- Lib/test/test_threading.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Lib/test/test_threading.py') diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 6b6c4d220a3..5f7c0a8801c 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -181,6 +181,7 @@ class ThreadTests(BaseTestCase): ctypes = import_module("ctypes") set_async_exc = ctypes.pythonapi.PyThreadState_SetAsyncExc + set_async_exc.argtypes = (ctypes.c_ulong, ctypes.py_object) class AsyncExc(Exception): pass @@ -189,9 +190,11 @@ class ThreadTests(BaseTestCase): # First check it works when setting the exception from the same thread. tid = threading.get_ident() + self.assertIsInstance(tid, int) + self.assertGreater(tid, 0) try: - result = set_async_exc(ctypes.c_long(tid), exception) + result = set_async_exc(tid, exception) # The exception is async, so we might have to keep the VM busy until # it notices. while True: @@ -237,7 +240,7 @@ class ThreadTests(BaseTestCase): # Try a thread id that doesn't make sense. if verbose: print(" trying nonsensical thread id") - result = set_async_exc(ctypes.c_long(-1), exception) + result = set_async_exc(-1, exception) self.assertEqual(result, 0) # no thread states modified # Now raise an exception in the worker thread. @@ -250,7 +253,7 @@ class ThreadTests(BaseTestCase): self.assertFalse(t.finished) if verbose: print(" attempting to raise asynch exception in worker") - result = set_async_exc(ctypes.c_long(t.id), exception) + result = set_async_exc(t.id, exception) self.assertEqual(result, 1) # one thread state modified if verbose: print(" waiting for worker to say it caught the exception") -- cgit v1.2.3