[英]Python: Exiting python.exe after Popen?
Small nagging issue: 小问题:
I have a python script that is working as expected, except when I select a menu option to Popen another python script: 我有一个按预期方式运行的python脚本,但当我选择菜单选项以Popen另一个python脚本时除外:
myPath = r"c:\Python27\myScript.py"
cmd = r"c:\Python27\python.exe '{}'".format(myPath)
py_process = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
When I run that snippet (in windows), the child process is kicked-off in the background as expected, but when I attempt to exit the primary script, but leave the child process running in the background: 当我运行该代码段(在Windows中)时,子进程将按预期在后台启动,但是当我尝试退出主脚本,但让子进程在后台运行时:
raise SystemExit
...an empty window "c:\\python27\\python.exe" remains. ...一个空窗口“ c:\\ python27 \\ python.exe”仍然存在。 I've tried other EXIT methods with a similar result. 我试过其他EXIT方法,结果相似。 Note: When I exit the primary script without running that snippet, the python window disappears as desired. 注意:当我不运行该代码段而退出主脚本时,python窗口将根据需要消失。
My goal is to leave no trace/window once the primary script is exited in all cases, but child process should remain running in background. 我的目标是在所有情况下都退出主脚本后不留下任何跟踪/窗口,但子进程应仍在后台运行。
Any suggestions to accomplish this goal? 有什么建议可以实现这个目标?
Thanks! 谢谢!
If you want to first communicate to the started process and then leave it alone to run further, you have a few options: 如果要先与已启动的进程进行通信,然后再让它继续运行,则有几种选择:
It does not create "a completely independent process" (that what python-daemon package does). 它不会创建“一个完全独立的进程”(python-daemon包会这样做)。 In other cases you should redirect to os.devnull child's stdin/stdout/stderr to avoid waiting for input and/or a spurious output to the terminal 在其他情况下,您应该重定向到os.devnull子级的stdin / stdout / stderr,以避免等待终端的输入和/或虚假输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.