【发布时间】:2018-12-18 03:55:39
【问题描述】:
我想从另一个 python 程序启动一个 python 程序并同时退出之前的程序。
我做了什么:
if(self.start_button.pression==1):
os.system('python program_to_launch.py')
sys.exit()
结果很明显,程序启动'program_to_launch.py'并等待它完成运行。
问题在于刚刚启动的程序内部的while循环。 它可以无限期使用。
这就是问题所在;之前的程序还在等待新程序的结束,不会执行`sys.exit()
我可以使用`杀死第一个程序
注意事项:
按照method provided by this answer,我无法导入要启动的程序,因为我想终止第一个程序
import program_to_launch
所以我认为这不是一个解决方案。
和命令exec file()
execfile('program_to_launch.py')
正如链接答案中所建议的那样,在执行 program_to_launch.py 时导入多个模块会出现问题
【问题讨论】:
标签: python exit termination