diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-23 15:48:39 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-03-23 14:48:39 +0100 |
commit | aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5 (patch) | |
tree | 39560da26771d1e10add697e558bb727639fdbb0 /Lib/test | |
parent | 1e2147b9d75a64df370a9393c2b5b9d170dc0afd (diff) | |
download | cpython-git-aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5.tar.gz |
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')
-rw-r--r-- | Lib/test/test_dummy_thread.py | 3 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 3 | ||||
-rw-r--r-- | Lib/test/test_threading.py | 9 |
3 files changed, 10 insertions, 5 deletions
diff --git a/Lib/test/test_dummy_thread.py b/Lib/test/test_dummy_thread.py index bb4bfe7a4d..0840be67d5 100644 --- a/Lib/test/test_dummy_thread.py +++ b/Lib/test/test_dummy_thread.py @@ -111,8 +111,7 @@ class MiscTests(unittest.TestCase): def test_ident(self): self.assertIsInstance(_thread.get_ident(), int, "_thread.get_ident() returned a non-integer") - self.assertNotEqual(_thread.get_ident(), 0, - "_thread.get_ident() returned 0") + self.assertGreater(_thread.get_ident(), 0) def test_LockType(self): self.assertIsInstance(_thread.allocate_lock(), _thread.LockType, diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index e6d8e5082f..9aeb28a898 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -393,6 +393,9 @@ class SysModuleTest(unittest.TestCase): thread_id = thread_info[0] d = sys._current_frames() + for tid in d: + self.assertIsInstance(tid, int) + self.assertGreater(tid, 0) main_id = threading.get_ident() self.assertIn(main_id, d) diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 6b6c4d220a..5f7c0a8801 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") |