国产日韩欧美一区二区三区综合,日本黄色免费在线,国产精品麻豆欧美日韩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人預約都是免費的,你也試試吧...

主站蜘蛛池模板: 堆龙德庆县| 桂平市| 怀远县| 通道| 百色市| 称多县| 敦化市| 贵南县| 平原县| 镶黄旗| 左云县| 桃江县| 城市| 广宗县| 双流县| 红原县| 兴隆县| 怀化市| 偏关县| 通河县| 霍林郭勒市| 福泉市| 青浦区| 宝山区| 黄浦区| 宝兴县| 芦山县| 沁源县| 阳新县| 紫金县| 平定县| 长沙县| 嵊泗县| 修文县| 石棉县| 太原市| 盘锦市| 金塔县| 莆田市| 龙游县| 容城县|