Closing a running program from a process

最后都变了- 提交于 2019-12-20 04:13:36

问题


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

Is there a way to execute the exit_option() ?


回答1:


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

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.



来源:https://stackoverflow.com/questions/41183390/closing-a-running-program-from-a-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!