Python结束线程的方法

    xiaoxiao2023-03-24  6

    import inspect import ctypes def _async_raise(tid, exctype): if not inspect.isclass(exctype): exctype = type(exctype) res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) if res == 0: raise ValueError("Invalid tid") elif res != 1: ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) raise RuntimeError("PyThreadState_SetAsyncExc failed") def stop_thread(thread): self._async_raise(thread.ident, SystemExit)

    以上代码由一个朋友提供~

    转载请注明原文地址: https://ju.6miu.com/read-1202638.html
    最新回复(0)