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