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

極客小將

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

資訊內容

python如何關閉線程

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

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

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

本教程操作環境:windows7系統、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指向要執行的方法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人預約都是免費的,你也試試吧...

主站蜘蛛池模板: 水富县| 股票| 临海市| 修武县| 德兴市| 南充市| 麦盖提县| 西盟| 吉林市| 琼中| 和田市| 西畴县| 修文县| 东山县| 玉龙| 大冶市| 石嘴山市| 永靖县| 彭山县| 且末县| 怀远县| 伊宁市| 常熟市| 岚皋县| 韩城市| 禄劝| 志丹县| 阿合奇县| 临沂市| 南通市| 安徽省| 奇台县| 施秉县| 婺源县| 鄯善县| 清丰县| 云南省| 黑河市| 南召县| 泾源县| 石楼县|