printing to a redirected stdout from a process that was called with "2>&1 > /dev/null &"

Pappy helgaorg at gmail.com
Mon Jan 29 18:12:37 EST 2007


SHORT VERSION:
Python File B changes sys.stdout to a file so all 'prints' are written 
to the file.  Python file A launches python file B with os.popen("./B 
2>&^1 >dev/null &").  Python B's output disappears into never-never 
land.

LONG VERSION:
I am working on a site that can kick off large-scale simulations.  It 
will write the output to an html file and a link will be emailed to 
the user.  Also, the site will continue to display "Loading..." if the 
user wants to stick around.

The simulation is legacy, and it basically writes its output to stdout 
(via simple print statements).  In order to avoid changing all these 
prints, I simply change sys.stdout before calling the output 
functions.  That works fine.  The whole thing writes to an html file 
all spiffy-like.

On the cgi end, all I want my (python) cgi script to do is check for 
form errors, make sure the server isn't crushed, run the simulation 
and redirect to a loading page (in detail, I write a constantly 
updating page to the location of the final output file.  When the 
simulation is done, the constantly updating file will be magically 
replaced).  The root problem is that the popen mechanism described 
above is the only way I've found to truly 'Detach' my simulation 
process.  With anything else, Apache (in a *nix environment) sits and 
spins until my simulation is done.  Bah.

Any ideas?

_jason




More information about the Python-list mailing list