subprocess monitoring in Windows?

Sam Bayer sam at sambayer.com
Mon Apr 22 23:12:07 EDT 2002


Hi all -

Lately, I've been forced to take a hard look at getting one of my 
Python/Tk apps running under Windows. This app monitors and controls 
subprocesses, essentially. I've been tripping over a lot of things, 
starting with the rather considerable differences in the Windows 
programming model, but I think I'm going to be able to handle the 
Windows equivalents of nonblocking reads and writes with pipes to 
subprocesses. However, there are a couple of odd omissions which I'm 
curious about, and I'm wondering whether they're just things that no one 
ever had the time to implement, or whether there's some deeper reason 
they're not around.

(1) The Unix popen2 module provides an object which gives the programmer 
simultaneous access to stdin/stdout for the subprocess as well as the 
process ID of the subprocess. For some reason, Mark Hammond's Windows 
extensions for Python don't do this. The C code which implements the 
popen2/3/4 functions hangs onto a process ID internally, but doesn't 
return it to the user; the only way to duplicate the Unix functionality 
is to translate the C code into Python (fortunately, someone posted 
something akin to such a translation a couple years ago). Has no one 
else ever found this to be useful?

(2) Apparently, Tcl/Tk replaced createfilehandler on Windows with the 
more general fileevent/channel abstraction starting with 8.0. However, 
this abstraction hasn't made it into Tkinter, and I can't find any hints 
on the newsgroup about how to get around this. A couple people reference 
the asyncore module, but I'm dealing with pipes, not sockets. What I'll 
probably do is write my own formatters to construct the appropriate 
fileevent calls, but I'm wondering what people have been doing in the 
meantime. I know I could use threads, but having had extensive annoying 
experience with mutexes in C, I'm not looking forward to having to 
duplicate the experience in Python if I don't have to.

Don't get me wrong; I love Python with all my heart, and I know that 
much of what makes it into the language is a generous gift of people's 
time. But I'm kind of puzzled that I'm finding it so hard to find 
references to workarounds for these omissions, and I'm wondering whether 
I'm missing something.

Thanks in advance -
Sam Bayer
The MITRE Corporation
sam at mitre.org




More information about the Python-list mailing list