gpt4 book ai didi

python - 用调用子进程替换当前进程?

转载 作者:IT老高 更新时间:2023-10-28 20:53:48 25 4
gpt4 key购买 nike

在python中,有没有办法在其中调用一个新进程,将相同的上下文(例如标准IO流)交给它,关闭当前进程,并将控制权交给被调用的进程?这将有效地“取代”该过程。

我有一个程序,我想重复它的行为。但是,它使用了第三方库,看来我可以真正杀死该库调用的线程的唯一方法是 exit() 我的 python 进程。

另外,它似乎可以帮助管理内存。

最佳答案

您可能对 os.execv() 感兴趣和 friend 们:

These functions all execute a new program, replacing the current process; they do not return. On Unix, the new executable is loaded into the current process, and will have the same process id as the caller. Errors will be reported as OSError exceptions.

关于python - 用调用子进程替换当前进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6743567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com