[Tutor] thread and os.pipe

Alan Gauld alan.gauld at btinternet.com
Sun Dec 9 01:25:59 CET 2007


"Tiago Saboga" <tiagosaboga at terra.com.br> wrote

>> Why not just set up outw to the output of Popen?
>
> Because in the more complicated case, the run function would have
> several steps, including some external processes with Popen. The 
> run()
> function will take care of determining which processes will run,
> according to the returncode of the first process), and will have to 
> do
> some cleaning in the end. But as this happens, I want my my main()
> function to analyse and print the output from the Popen while the
> external processes are running.

OK, I suspected this might be the case.
In that situation I'd still consider running the initial Popen without
threads and capturing the output but then once you know which
secondary proceses need running and what cleanup needs doing
you could perform those parts in a thread. In other words only
use threads where you truly need parallel processing in the
same process.

> test. I am sorry if I am not clear enough, I am still learning both
> python and english!

Both are looking fine to me :-)

> single class, subclassing the qt-designer/pyuic generated one. I am 
> trying
> to make my two auxiliary classes totally independent, as I would 
> love
> to make a curses version later. So I have a Converter class which 
> does
> the actual job of calling the back-end, but I want the gui to be
> updated to show the output from the commands. What I want to do
> is make the doit() method of the Converter class return a pipe,
> through which it will then send the output of the programs.

I'm still not convinced that a pipe is the best solution here.
You could simply register the UI View with the converter (in usual MVC
design pattern) and get the converter to either send updates to the
UI (or notify the UI to request updates) as needed. That way you
only need a regular Python method in the Converter to deliver the
data and another in the UI code to respond to the notification.
No pipes or queues required.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list