473,289 Members | 1,840 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,289 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 2164
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"
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

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.