国产日韩欧美一区二区三区综合,日本黄色免费在线,国产精品麻豆欧美日韩ww,色综合狠狠操

極客小將

您現在的位置是:首頁 » python編程資訊

資訊內容

python如何關閉線程

極客小將2021-03-07-
簡介python關閉線程的方法:首先導入threading,定義一個方法;然后定義線程,target指向要執(zhí)行的方法,啟動它;最后停止線程,代碼為【stop_thread(myThread)】。本教程操作環(huán)境:windows7系統(tǒng)、python3.9版,DELLG3電腦。python關閉線程的方法:一、

python關閉線程的方法:首先導入threading,定義一個方法;然后定義線程,target指向要執(zhí)行的方法,啟動它;**后停止線程,代碼為【stop_thread(myThread)】。yxH少兒編程網-https://www.pxcodes.com

yxH少兒編程網-https://www.pxcodes.com

本教程操作環(huán)境:windows7系統(tǒng)、python3.9版,DELL G3電腦。yxH少兒編程網-https://www.pxcodes.com

python關閉線程的方法:yxH少兒編程網-https://www.pxcodes.com

一、啟動線程yxH少兒編程網-https://www.pxcodes.com

首先導入threadingyxH少兒編程網-https://www.pxcodes.com

import threading

然后定義一個方法yxH少兒編程網-https://www.pxcodes.com

def serial_read(): ... ...

然后定義線程,target指向要執(zhí)行的方法yxH少兒編程網-https://www.pxcodes.com

myThread = threading.Thread(target=serial_read)

啟動它yxH少兒編程網-https://www.pxcodes.com

myThread.start()

二、停止線程yxH少兒編程網-https://www.pxcodes.com

不多說了直接上代碼yxH少兒編程網-https://www.pxcodes.com

import inspect import ctypes def _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)

停止線程yxH少兒編程網-https://www.pxcodes.com

stop_thread(myThread)

相關免費學習推薦:python視頻教程yxH少兒編程網-https://www.pxcodes.com

以上就是python如何關閉線程的詳細內容,更多請關注少兒編程網其它相關文章!yxH少兒編程網-https://www.pxcodes.com

預約試聽課

已有385人預約都是免費的,你也試試吧...

主站蜘蛛池模板: 德保县| 甘洛县| 临泉县| 昂仁县| 桂东县| 公主岭市| 班玛县| 杭锦后旗| 烟台市| 洛隆县| 雷波县| 东明县| 庄河市| 伊吾县| 邵阳县| 辽中县| 裕民县| 日照市| 新源县| 信丰县| 贵州省| 玉门市| 娄烦县| 南城县| 中山市| 江永县| 上饶县| 建德市| 开封市| 竹山县| 永兴县| 宁明县| 湛江市| 富锦市| 普定县| 清苑县| 许昌县| 富顺县| 翁牛特旗| 镶黄旗| 安福县|