subprocess & redirect
Philip Semanchuk <[email protected]>
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I'm trying to spawn a subprocess in response to a form submission and
it isn't behaving as I'd like. The subprocess will run for a long time
(minutes or hours, possibly even days) and so I want to spawn it
*asynchronously* and then immediately redirect the user to a page that
says "Your job has been started, go get a cup of coffee" etc. However,
the redirect doesn't occur until the spawned process completes.
There's an example below. In the example, foo.py is just a stub that
calls time.sleep(10). I tried spawning foo.py using the subprocess
module (from Python 2.4) and also using os.spawnl(os.P_NOWAIT...). The
two should be equivalent, and indeed neither gives me asynchronous
execution although I expect that both would. They spawn an asynchronous
process when called outside of the context of Spyce, so there's some
interaction here that I don't understand. Can anyone enlighten me? I'd
appreciate it.
Thanks
Philip
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>test</title>
</head>
<body>
<p>redirect test</p>
[[.import name=redirect]]
[[\
import subprocess
import os
TheLongRunningProcess = "/usr/local/MyStuff/src/foo.py"
subprocess.Popen(["python", TheLongRunningProcess])
#os.spawnl(os.P_NOWAIT, "/usr/bin/python", "/usr/bin/python",
TheLongRunningProcess)
redirect.external("http://google.com")
# This doesn't make a difference
raise spyceDone
]]
</body>
</html>
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642