62 | def _raise_thread_exception_cpython(thread_id, exception): |
63 | exctype = (exception if inspect.isclass(exception) else type(exception)).__name__ |
64 | thread_id = ctypes.c_long(thread_id) |
65 | exception = ctypes.py_object(exception) |
66 | count = ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, exception) |
67 | if count == 0: |
68 | logger.critical("Failed to set exception (%s) in thread %r.", exctype, thread_id.value) |
69 | elif count > 1: |
70 | logger.critical("Exception (%s) was set in multiple threads. Undoing...", exctype) |
71 | ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, ctypes.c_long(0)) |