Python-从Web应用程序启动长时间运行的进程 [英] Python - Launch a Long Running Process from a Web App
问题描述
我有一个需要启动长时间运行过程的python Web应用程序.问题是我不希望它等待过程完成.只需启动并完成.
I have a python web application that needs to launch a long running process. The catch is I don't want it to wait around for the process to finish. Just launch and finish.
我正在Windows XP上运行,并且该Web应用程序正在IIS下运行(如果有的话).
I'm running on windows XP, and the web app is running under IIS (if that matters).
到目前为止,我尝试过popen,但这似乎没有用.它一直等到子进程完成.
So far I tried popen but that didn't seem to work. It waited until the child process finished.
推荐答案
好,我终于明白了!这似乎可行:
Ok, I finally figured this out! This seems to work:
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]错误的文件描述符"
Note: I added shell=True. Otherwise calling print in the child process gave me the error "IOError: [Errno 9] Bad file descriptor"
DETACHED_PROCESS
是过程创建标志,该标志传递给基础WINAPI
DETACHED_PROCESS
is a Process Creation Flag that is passed to the underlying WINAPI CreateProcess function.
这篇关于Python-从Web应用程序启动长时间运行的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!