diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-23 13:48:39 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-03-23 13:48:39 (GMT) |
commit | aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5 (patch) | |
tree | 39560da26771d1e10add697e558bb727639fdbb0 /Lib/test/test_threading.py | |
parent | 1e2147b9d75a64df370a9393c2b5b9d170dc0afd (diff) | |
download | cpython-aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5.zip cpython-aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5.tar.gz cpython-aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5.tar.bz2 |
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().
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r-- | Lib/test/test_threading.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 6b6c4d2..5f7c0a8 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") |