473,385 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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

Jan 29 '07 #1
3 2168
On Mon, Jan 29, 2007 at 03:12:37PM -0800, Pappy wrote:
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
>
_jason

--
http://mail.python.org/mailman/listinfo/python-list
Jan 30 '07 #2
On Tue, Jan 30, 2007 at 10:42:22AM -0500, Jason Persampieri wrote:
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).

On 1/30/07, Chris Lambacher <[1]ch***@kateandchris.netwrote:

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
>
_jason
>
--
[3]http://mail.python.org/mailman/listinfo/python-list

References

Visible links
1. mailto:ch***@kateandchris.net
2. http://docs.python.org/dev/lib/module-subprocess.html
3. http://mail.python.org/mailman/listinfo/python-list
Jan 30 '07 #3
On Jan 29, 7:12 pm, "Pappy" <helga...@gmail.comwrote:
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

Mar 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric Osman | last post by:
Hi, I'm looking for a javascript function that will convert input such as this: <CLUB Code=" into this: &lt;CLUB Code=&quot;
2
by: Laermans_k | last post by:
Hi, Does anyone have a solution to use the <input type="file" id="filechooser"> and the <input type="submit" id="submitbutton"> in 1 button click? I've already tried to create a javascript...
4
by: barney | last post by:
Hello, I' m using .NET System.Xml.XmlDOcument. When I do the following: XmlDocument xml = new XmlDocument(); xml.Load("blah"); .... xml.Save("blub"); I've got the problem that the following...
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
3
by: Carpe Diem | last post by:
Hello I have an aspx page that loses Session("user") value after a few minutes even after I set <sessionState mode="InProc" cookieless="false" timeout="300"> in web.config and wrote function...
5
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot;...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
3
by: kaleshwar | last post by:
Hello, I want to ask that what is the difference between to define #include<stdio.h> and #include" filename.c"
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.