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

極客小將

您現(xiàn)在的位置是:首頁(yè) » python編程資訊

資訊內(nèi)容

python如何關(guān)閉線(xiàn)程

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

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

yxH少兒編程網(wǎng)-https://www.pxcodes.com

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

python關(guān)閉線(xiàn)程的方法:yxH少兒編程網(wǎng)-https://www.pxcodes.com

一、啟動(dòng)線(xiàn)程yxH少兒編程網(wǎng)-https://www.pxcodes.com

首先導(dǎo)入threadingyxH少兒編程網(wǎng)-https://www.pxcodes.com

import threading

然后定義一個(gè)方法yxH少兒編程網(wǎng)-https://www.pxcodes.com

def serial_read(): ... ...

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

myThread = threading.Thread(target=serial_read)

啟動(dòng)它yxH少兒編程網(wǎng)-https://www.pxcodes.com

myThread.start()

二、停止線(xiàn)程yxH少兒編程網(wǎng)-https://www.pxcodes.com

不多說(shuō)了直接上代碼yxH少兒編程網(wǎng)-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)

停止線(xiàn)程yxH少兒編程網(wǎng)-https://www.pxcodes.com

stop_thread(myThread)

相關(guān)免費(fèi)學(xué)習(xí)推薦:python視頻教程yxH少兒編程網(wǎng)-https://www.pxcodes.com

以上就是python如何關(guān)閉線(xiàn)程的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注少兒編程網(wǎng)其它相關(guān)文章!yxH少兒編程網(wǎng)-https://www.pxcodes.com

預(yù)約試聽(tīng)課

已有385人預(yù)約都是免費(fèi)的,你也試試吧...

主站蜘蛛池模板: 禹州市| 农安县| 奉节县| 安庆市| 正镶白旗| 鄂伦春自治旗| 舟曲县| 靖宇县| 施秉县| 嘉祥县| 曲靖市| 攀枝花市| 秀山| 宝清县| 郸城县| 琼海市| 会东县| 海安县| 连南| 汤阴县| 东港市| 贡山| 南昌市| 古浪县| 东丰县| 平度市| 长寿区| 府谷县| 开化县| 济宁市| 屏南县| 龙州县| 肇庆市| 色达县| 东兰县| 建瓯市| 桦川县| 临西县| 改则县| 鄄城县| 墨竹工卡县|