在python中生成非子进程 [英] Spawning a non-child process in python

查看:151
本文介绍了在python中生成非子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在python中创建一个进程,该进程允许在子进程仍在运行时退出调用进程.有效的方法是什么?

I need to create spawn off a process in python that allows the calling process to exit while the child is still running. What is an effective way to do this?

注意:我正在UNIX环境上运行.

Note: I'm running on a UNIX environment.

推荐答案

在类似Unix的操作系统中,终止父进程不会终止子进程,因此您无需执行任何特殊操作.只需使用subprocess.Popen启动子流程并终止主流程.孤立进程将被init自动采用.

Terminating the parent process does not terminate child processes in Unix-like operating systems, so you don't need to do anything special. Just start your subprocesses with subprocess.Popen and terminate the main process. The orphaned processes will automatically be adopted by init.

这篇关于在python中生成非子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆