Terminating processes on Windows (handles and IDs)

geoffbache geoff.bache at jeppesen.com
Mon Jun 23 11:33:33 EDT 2008


Hi all,

I've always wondered why os.kill isn't supported on Windows. I found a
discussion somewhere from 2006 about this so it seems others have
wanted it, but still nothing. So I have a half-baked solution
involving calling "taskkill" on Windows Vista or "tskill" on Windows
XP via the shell. I feel there has to be a better way.

I'm also fairly confused about when I've got an ID and when I've got a
handle. The subprocess module gives me IDs which the above programs
accept, but other ways of spawning processes give me process handles
(while referring to them as process IDs in the docs...) and I don't
know how to kill a process with these. Besides, I've found an
amazingly useful PyGTK method, gobject.child_watch_add, which does
exactly what I want on UNIX but wants process handles on Windows. So I
can't use it in conjunction with subprocess there, and if I use some
other way of spawning processes I can't clean them up later.

Is there any way to convert one of these numbers to the other? Or to
get a process handle out of subprocess?
(There must be one down there somewhere, surely?)

Sorry for rambling a bit, am confused.

Regards,
Geoff Bache



More information about the Python-list mailing list