[Baypiggies] Subprocess: Common problem/common pattern

Glen Jarvis glen at glenjarvis.com
Sat Oct 2 19:26:31 CEST 2010


An event call back is *exactly* the kind of thing that I'm looking for. I
hadn't seen these yet... I'll review the PEPs now.

Thank you!


Glen

On Sat, Oct 2, 2010 at 10:23 AM, James Tatum <jtatum at gmail.com> wrote:

> Google turns up a number of requests for this functionality, and a draft
> PEP[0].
>
> Did you see this module[1]? It adds an event callback for subprocess
> output.
>
> [0] http://www.python.org/dev/peps/pep-3145/
> [1]
> http://code.activestate.com/recipes/576957-asynchronous-subprocess-using-asyncore/
>
> On Sat, Oct 2, 2010 at 10:17 AM, Glen Jarvis <glen at glenjarvis.com> wrote:
> > I'm sorry, I thought I was more clear with my test case. Obviously, I was
> > not.
> >
> > The problem is this:
> >     Python programs can call subprocesses. The python program can wait
> until
> > the subprocess has finished and print the output captured. However, what
> we
> > want is to print the output immediately as it is generated.
> >     So, instead of waiting for the subprocess to finish, the python
> program
> > could continue -- printing the results as given by the subprocess.  From
> the
> > way the test case is written, the communicate() method will wait until
> the
> > subprocess is finished *before* it prints the results that were found.
> > Thanks for asking for clarification. You weren't the only person asking,
> so
> > obviously I wasn't clear enough in defining the problem.
> >
> > Cheers,
> >
> > Glen
> > On Sat, Oct 2, 2010 at 10:13 AM, Aahz <aahz at pythoncraft.com> wrote:
> >>
> >> On Sat, Oct 02, 2010, Glen Jarvis wrote:
> >> >
> >> > I've now seen a common problem come up several times. And, I imagine
> >> > there
> >> > is a common solution to this problem that I don't know.
> >>
> >> Could you explain what the problem is?  I think it's related to
> buffering
> >> and pipes, but it's not clear from your post.
> >> --
> >> Aahz (aahz at pythoncraft.com)           <*>
> >> http://www.pythoncraft.com/
> >>
> >> "If you think it's expensive to hire a professional to do the job, wait
> >> until you hire an amateur."  --Red Adair
> >> _______________________________________________
> >> Baypiggies mailing list
> >> Baypiggies at python.org
> >> To change your subscription options or unsubscribe:
> >> http://mail.python.org/mailman/listinfo/baypiggies
> >
> >
> >
> > --
> > Whatever you can do or imagine, begin it;
> > boldness has beauty, magic, and power in it.
> >
> > -- Goethe
> >
> > _______________________________________________
> > Baypiggies mailing list
> > Baypiggies at python.org
> > To change your subscription options or unsubscribe:
> > http://mail.python.org/mailman/listinfo/baypiggies
> >
>



-- 
Whatever you can do or imagine, begin it;
boldness has beauty, magic, and power in it.

-- Goethe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20101002/66a455d1/attachment.html>


More information about the Baypiggies mailing list