好吧,我终于明白了!这似乎可行:
from subprocess import Popenfrom win32process import DETACHED_PROCESSpid = Popen(["C:python24python.exe", "long_run.py"],creationflags=DETACHED_PROCESS,shell=True).pidprint pidprint 'done' #I can now close the console or anything I want and long_run.py continues!
注意:我添加了shell = True。否则在子进程中调用print会给我错误“ IOError:[Errno 9]错误的文件描述符”
DETACHED_PROCESS是一个过程创建标志,该标志被传递给基础WINAPI
CreateProcess函数。



