从进程中关闭正在运行的程序 [英] Closing a running program from a process

查看:115
本文介绍了从进程中关闭正在运行的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从子进程中关闭程序? 例如:

How can I close a program from a child process? For exanple:

import easygui
import multiprocessing

def func():
    reply=easygui.buttonbox("start?",image="F:\project\phonber.png",choices=['yes','no'])
    if reply=="yes":
        exit_option()


if __name__=='__main__':
    p=multiprocessing.Process(target=func,args=())
    t=p.start()
    while True:
        None

是否可以执行exit_option()?

推荐答案

您忘了实际调用该函数:

Your forgot to actually call the function:

import easygui
import multiprocessing

def func():
    reply=easygui.buttonbox("start?",image="F:\project\phonber.png",choices=['yes','no'])
    if reply=="yes":
        exit_option()

func()


if __name__=='__main__':
    p=multiprocessing.Process(target=func,args=())
    t=p.start()
    while True:
        None

然后,要杀死一个正在运行的进程,当然有很多选择.最明显的是psutilkillterminate方法,或os的kill方法.两者均显示在此处.

Then, to actually kill a running process there are, of course, many options. The most obvious ones being psutil its kill or terminate method, or os its kill method. Both as shown here.

这篇关于从进程中关闭正在运行的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆