mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
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().
This commit is contained in:
parent
1e2147b9d7
commit
aefa7ebf0f
27 changed files with 116 additions and 88 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue