国产探花免费观看_亚洲丰满少妇自慰呻吟_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中實現強制關閉線程的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麦盖提县| 昔阳县| 临漳县| 山阳县| 文安县| 泉州市| 南京市| 玉树县| 新巴尔虎左旗| 扎赉特旗| 儋州市| 金昌市| 安徽省| 冕宁县| 积石山| 时尚| 黔西县| 西乌珠穆沁旗| 保定市| 乌什县| 壶关县| 文登市| 城口县| 兰溪市| 平塘县| 太仓市| 芦山县| 岳池县| 张掖市| 南投县| 伊宁市| 宁津县| 乐安县| 凤阳县| 安国市| 黄浦区| 广饶县| 阳江市| 策勒县| 邻水| 宁化县|