def stop_thread(tid, exctype=SystemExit): tid = ctypes.c_long(tid.ident) if not inspect.isclass(exctype): exctype = type(exctype) res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) if res == 0: raise ValueError("Invalid thread id") elif res != 1:...
= 1: ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) raise SystemError("PyThreadState_SetAsyncExc failed") def stop_thread(thread): _async_raise(thread.ident, SystemExit) class MyThread(threading.Thread): def run(self): while True: time.sleep(1) print("Thread is running...") if...