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

極客小將

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

資訊內(nèi)容

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

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

python關(guān)閉線程的方法:首先導(dǎo)入threading,定義一個方法;然后定義線程,target指向要執(zhí)行的方法,啟動它;**后停止線程,代碼為【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)閉線程的方法:yxH少兒編程網(wǎng)-https://www.pxcodes.com

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

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

import threading

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

def serial_read(): ... ...

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

myThread = threading.Thread(target=serial_read)

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

myThread.start()

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

不多說了直接上代碼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)

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

stop_thread(myThread)

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

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

預(yù)約試聽課

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

主站蜘蛛池模板: 汝城县| 玉龙| 固镇县| 罗甸县| 多伦县| 平顺县| 朔州市| 虞城县| 临邑县| 武安市| 库尔勒市| 军事| 武陟县| 广安市| 瑞金市| 洪泽县| 乌海市| 思茅市| 德保县| 沭阳县| 错那县| 宣化县| 大方县| 和龙市| 孟村| 门头沟区| 涡阳县| 沂水县| 水城县| 承德县| 高邮市| 庆阳市| 三明市| 海阳市| 信丰县| 教育| 永善县| 揭阳市| 吴桥县| 思茅市| 手游|