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

P

Pappy

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
 
C

Chris Lambacher

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?
The subprocess module is probably a good starting point:
http://docs.python.org/dev/lib/module-subprocess.html

It will allow you greater control over what happens with the output of a
process that you start. Specifically look at the the stdout and stderr
arguments to Popen. You can provide these with an open file descriptor or a
file object and it will dump the output into there.

-Chris
 
C

Chris Lambacher

Sadly, the group is tied to Python 2.3 for now.
Subprocess for 2.2 and 2.3:
http://www.lysator.liu.se/~astrand/popen5/

Win32 installers for subversion for 2.2 and 2.3:
http://www.lysator.liu.se/~astrand/popen5/

-Chris
Actually, I got around this problem by using an intermediate process that
happens to handle output on its own (bsub).


The subprocess module is probably a good starting point:
[2]http://docs.python.org/dev/lib/module-subprocess.html

It will allow you greater control over what happens with the output of a
process that you start. Specifically look at the the stdout and stderr
arguments to Popen. You can provide these with an open file descriptor
or a
file object and it will dump the output into there.

-Chris

References

Visible links
1. mailto:[email protected]
2. http://docs.python.org/dev/lib/module-subprocess.html
3. http://mail.python.org/mailman/listinfo/python-list
 
G

gregpinero

SHORT VERSION:pythonFile B changes sys.stdout to a file so all 'prints' are written
to the file. Pythonfile A launchespythonfile B with os.popen("./B
2>&^1 >dev/null &"). PythonB'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 thecgiend, all I want my (python)cgiscript to do is check for
form errors, make sure the server isn't crushed, run the simulation
and redirect to aloadingpage (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


Did you ever find your answer Mr. _jason? I'm trying to do the same
thing now but even with the subprocess module the broswer still says
loading until the subprocess is done.

Is there truly NO way to kick of a process and be done with it
forever?

-Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top