472,363 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,363 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 2085
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
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.