terminating an inactive process
Trent Mick
trentm at ActiveState.com
Mon Apr 4 13:50:25 EDT 2005
[Earl Eiland wrote]
> I'm running a PyWin program that executes another program using
> subprocess.Popen(). Unfortunately, this other program isn't well
> behaved, and frequently terminates without terminating its process.
> After this happens enough times, all my memory is tied up, and the
> machine crashes.
>
> Using subprocess.poll(), I can keep my program from hanging, by timing
> out the process, and starting anew. This still leaves the previous
> process hogging memory. How do I kill the old process in Windows?
You might be able to use or borrow code from my process.py module.
process.py is very similar to Python 2.4's subprocess. It provides a
ProcessOpen class (similar to subprocess' Popen). A ProcessOpen instance
has wait() and kill() methods that work fine on Windows. Under the hood
they are using the Win32 API WaitForSingleObject() and
TerminateProcess() functions.
http://starship.python.net/~tmick/
Yes, I haven't updated process.py in a while. :) It works fine with
Python 2.3 and 2.4 (despite only saying Python 2.2 there). It *does*
rely on the PyWin32 extensions being installed with you Python
installation -- which you'll already have if you use ActivePython or
which you can install separately from here:
http://sourceforge.net/project/showfiles.php?group_id=78018
Cheers,
Trent
--
Trent Mick
TrentM at ActiveState.com
More information about the Python-list
mailing list