[Chicago] Wrapping an interactive console application

Atul Varma varmaa at gmail.com
Mon Apr 21 20:39:37 CEST 2008

On Mon, Apr 21, 2008 at 11:33 AM, Feihong Hsu <hsu.feihong at yahoo.com> 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.

Have you tried busting the thread as a daemonic thread using
thread.setDaemon(True)?  You might also be able to bust its death from
another thread by importing either ctypes or win32all and using the
win32 TerminateProcess() call with the popen object's "pid" attribute.
(Fortunately, it looks like 2.6 will actually include this
functionality in subprocess, from what I've seen on python-dev

Also, I've found that reading from Popen.stdout can get problematic
due to blocking issues on Windows--if you run into issues, you may
want to consider pointing the subprocess' stdout to a file and reading
from that, as messy as it sounds. :/

Hope that helps...

- Atul

More information about the Chicago mailing list