[Chicago] Wrapping an interactive console application

John Jacobsen john at mail.npxdesigns.com
Mon Apr 21 20:47:59 CEST 2008


Hi Feihong,

The problem is probably not with Popen but with the threads.  I don't  
know if this works on Windows, but if you are using (or can use) the  
threading.Thread object, try this:

    def _threadFunction():
        # popen Stuff

    t = threading.Thread(target=_threadFunction)
    t.setDaemon(True) # Make thread die if program exits
    t.thread.start()

The setDaemon method has worked well for me for this sort of problem  
(under Mac or Linux).  Let us know if it works for you!

Good luck,
John

On Apr 21, 2008, at 1:33 PM, Feihong Hsu wrote:

> Hi everyone,
>
> Is there anyone here who has experience with the following problem? I
> am trying to write a Python program that wraps around an interactive
> console application. I use the subprocess module for this. I start a
> separate thread which uses the Popen.stdout attribute to get the
> output from the console application. Everything basically works OK,
> except that I can't easily quit my Python program. Even calling
> sys.exit doesn't work! It looks like my thread that's reading from
> standard output just refuses be killed.
>
> BTW, I'm developing this program on Windows.
>
> Thanks,
> Feihong
>
>
>
>
>        
> ______________________________________________________________________ 
> ______________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.  http:// 
> mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago

John Jacobsen
NPX Designs, Inc.

Contact info: http://www.npxdesigns.com/contact.html



More information about the Chicago mailing list