我想知道如何在main中启动进程,然后在def函数中终止它。在我的代码中,我有一个进程运行一个感兴趣的应用程序,然后是另一个进程,它使用Tkinter运行一个简单的GUI,等待buton被按下。当按下这个按钮时,我希望进程被终止。例如:
def pro_a():
#Runs the application
def pro_b():
root.mainloop() # Runs the GUI
def buttonCallBack()
#I want to terminate the processes here
#I've tried doing: p1.terminate()
b = Button(frame, .........., command = buttonCallBack)
b.place(......)
if __name__ == '__main__':
p1 = Process(target=pro_b)
p2 = Process(target=pro_a)
p1.start()
p2.start()
当我尝试这样做时,它会给我一个错误:AttributeError: 'NoneType' object has no attribute 'terminate'
但是当我试图在main
中终止它时,它是有效的。但那不是我想要的。为了清楚起见,我需要在main中启动进程,然后在按下按钮后结束它们。在
不要在子进程中启动
pro_b()
,只需直接调用pro_b()
。我认为pro_b()
子进程在没有引用pro_a()
子进程的情况下结束。如果您直接调用pro_b()
,那么您将从父进程中杀死pro_a()
子进程。在相关问题 更多 >
编程相关推荐