如何从python调用程序,而不用等待它返回 [英] how to call a program from python without waiting for it to return

查看:2669
本文介绍了如何从python调用程序,而不用等待它返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从python调用程序,而不等待它返回?我创建了一个脚本,它将程序复制到目录并运行该程序。但是当我从python调用程序,python脚本不退出,直到我启动的程序退出。我试过os.system和Popen。有没有其他方法可以做到这一点?

is there a way to call a program from python without waiting for it to return? i created a script which copies a program to a directory and runs that program. but when i call the program from python, the python script does not exit until the program i launched exits. i have tried os.system and Popen. is there another way to do this?

添加信息:
os.spawnl与os.P_DETACH仍然不工作;根据文档,P_DETACH类似于P_NOWAIT,但新进程从调用进程的控制台分离。但它仍然以某种方式附加到我的调用过程(调用脚本不会退出,直到任何被调用的可执行文件返回)

Added info: os.spawnl with os.P_DETACH still doesn't work; according to the docs, "P_DETACH is similar to P_NOWAIT, but the new process is detached from the console of the calling process". but it is still somehow attached to my calling process (calling script won't quit until any of the called executables return)

程序:

os.system("start test.exe")
print "Done"

在执行test.exe后,它将打印完成。但它不会终止脚本的执行(脚本进程仍在运行)。尝试创建一个守护线程和Popen与P_DETACH,仍然没有。

after it executes test.exe, it prints Done. but it does not terminate the script's execution (script process still running). tried creating a daemon thread and Popen with a P_DETACH, still no go.

推荐答案

我发布了一个解决方案如何分离进程上一个问题

I posted a solution how to detach a process in a previous question.

这篇关于如何从python调用程序,而不用等待它返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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