问题描述
在python中,有没有办法调用一个新进程,将相同的上下文交给它,例如标准IO流,关闭当前进程,并将控制权交给被调用的进程?这将有效地取代"流程.
In python, is there a way to invoke a new process in, hand it the same context, such as standard IO streams, close the current process, and give control to the invoked process? This would effectively 'replace' the process.
我有一个程序,我想重复该程序的行为.但是,它使用了第三方库,并且似乎我可以真正杀死该库调用的线程的唯一方法是 exit() 我的 python 进程.
I have a program whose behavior I want to repeat. However, it uses a third-party library, and it seems that the only way that I can truly kill threads invoked by that library is to exit() my python process.
另外,它似乎有助于管理内存.
Plus, it seems like it could help manage memory.
推荐答案
您可能对 os.execv()
和朋友们:
You may be interested in os.execv()
and friends:
这些函数都执行一个新的程序,替换当前的过程;他们不回来.在 Unix 上,加载新的可执行文件进入当前进程,并将具有与当前进程相同的进程 ID呼叫者.错误将报告为 OSError 异常.
这篇关于用调用子流程替换当前流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!