python运行停留窗口_如何从Tkinter窗口立即停止Python进程?

如果它是一个线程,你可以使用低级线程(或Python 3中的_thread)模块通过调用thread.exit()来杀死具有异常的线程.

> thread.exit():提高SystemExit异常.什么时候没抓到

这将导致线程以静默方式退出.

一个更干净的方法(取决于你的处理设置如何)将指示线程停止处理并使用实例变量退出,然后从主线程调用join()方法等待线程退出.

例:

class MyThread(threading.Thread):

def __init__(self):

super(MyThread, self).__init__()

self._stop_req = False

def run(self):

while not self._stop_req:

pass

# processing

# clean up before exiting

def stop(self):

# triggers the threading event

self._stop_req = True;

def main():

# set up the processing thread

processing_thread = MyThread()

processing_thread.start()

# do other things

# stop the thread and wait for it to exit

processing_thread.stop()

processing_thread.join()

if __name__ == "__main__":

main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值