简体   繁体   English

退出后杀死python应用程序

[英]killing python application after exiting it

I'm starting finishing off my new simple app and because Python isn't my main programming language I'm struggling a lot.我开始完成我的新简单应用程序,因为 Python 不是我的主要编程语言,所以我很挣扎。 I would like to add a function which would kill everything - every service in the app, after clicking an exit button.在单击退出按钮后,我想添加一个可以杀死所有内容的功能-应用程序中的每个服务。 (So maybe with a global variable?) I want to do it as simple as possible. (所以也许有一个全局变量?)我想尽可能简单。 I was wondering if there is anything similar to isServerOn or so.我想知道是否有类似 isServerOn 的东西。 What I have so far is just this code below and if there would be a chance to add just one or few lines then it would be the best.到目前为止,我所拥有的只是下面的这段代码,如果有机会只添加一行或几行,那将是最好的。 Thank you all so much!!非常感谢大家!!

import sys
    def quit()
       sys.exit()

To stop a python script use the keyboard: Ctrl + C要停止 python 脚本,请使用键盘: Ctrl + C

To stop it using code you can use these sections (Python 3) :要使用代码停止它,您可以使用以下部分(Python 3):

raise SystemExit

you can also use:您还可以使用:

import sys
sys.exit()

or:或者:

exit()

or:或者:

import os
os._exit(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM