在 Python 中运行一个没有父进程的子进程

编程入门 行业动态 更新时间:2024-10-25 00:37:12
本文介绍了在 Python 中运行一个没有父进程的子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个程序正在另一个程序中运行.父程序在子进程运行时冻结.有没有办法在操作系统中将子进程作为父进程本身运行?

I have a program I'm running within another. The parent program freezes up while the child process is running. Is there a way to run the child process in the OS as a parent process itself?

推荐答案

您可以使用 subprocess.Popen,假设您真的想启动一个与父 Python 脚本完全分离的程序:

You can use subprocess.Popen, assuming you're really trying to launch a program that's completely separate from the parent Python script:

import subprocess subprocess.Popen(["command", "-a", "arg1", "-b", "arg2"])

这将启动 command 作为调用脚本的子进程,不会阻塞等待它完成.如果父进程退出,子进程将继续运行.

This will launch command as a child process of the calling script, without blocking to wait for it to finish. If the parent exits, the child process will continue to run.

更多推荐

在 Python 中运行一个没有父进程的子进程

本文发布于:2023-08-05 05:43:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1303026.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!