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

主站蜘蛛池模板: 嘉义市| 乐都县| 德钦县| 庆云县| 南涧| 崇州市| 玉林市| 汪清县| 汨罗市| 阿坝| 龙岩市| 巴马| 平定县| 仙桃市| 松潘县| 贺州市| 廉江市| 宁陵县| 板桥市| 库车县| 平陆县| 峡江县| 安阳市| 孟州市| 绥棱县| 朔州市| 玉门市| 渝北区| 四子王旗| 丰台区| 庆阳市| 荆州市| 马边| 远安县| 清镇市| 来宾市| 恭城| 汉中市| 石河子市| 兴安盟| 玉龙|