如何从 python 调用程序而不等待它返回

how to call a program from python without waiting for it to return(如何从 python 调用程序而不等待它返回)
本文介绍了如何从 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 之后,它会打印 Done.但它不会终止脚本的执行(脚本进程仍在运行).尝试创建一个守护线程并使用 P_DETACH Popen,仍然不行.

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.

推荐答案

在 Windows 下,如果你使用 shell START 命令调用程序,你应该能够释放"父进程并允许它退出.在 DOS 提示符下尝试 START/? 以了解更多信息.

Under Windows, if you invoke the program using the shell START command you should be able to "release" the parent process and allow it to exit. Try START /? at the DOS prompt to learn more.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)