国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

在python中實現強制關閉線程的示例

2020-02-16 00:49:19
字體:
來源:轉載
供稿:網友

如下所示:

import threadingimport timeimport inspectimport ctypesdef _async_raise(tid, exctype):  """raises the exception, performs cleanup if needed"""  tid = ctypes.c_long(tid)  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:   # """if it returns a number greater than one, you're in trouble,    # and you should call it again with exc=NULL to revert the effect"""    ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)   raise SystemError("PyThreadState_SetAsyncExc failed")def stop_thread(thread):  _async_raise(thread.ident, SystemExit)class TestThread(threading.Thread):  def run(self):   print   "begin"   while True:     time.sleep(0.1)   print('end')if __name__ == "__main__":  t = TestThread()  t.start()  time.sleep(1)  stop_thread(t)  print('stoped') 

以上這篇在python中實現強制關閉線程的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海口市| 祁门县| 碌曲县| 文安县| 九江县| 得荣县| 耿马| 四会市| 兴隆县| 延吉市| 墨脱县| 康马县| 临朐县| 遂川县| 林口县| 新沂市| 正镶白旗| 娄烦县| 上蔡县| 苏尼特右旗| 武夷山市| 西宁市| 永福县| 乐亭县| 江门市| 余庆县| 隆化县| 康定县| 扶风县| 哈巴河县| 社旗县| 潮安县| 原阳县| 迁安市| 巴东县| 宁蒗| 颍上县| 项城市| 合肥市| 清丰县| 全南县|