[python-win32] TerminateProcess issues
Sean Q. Hendricks
shendric at uga.edu
Thu Sep 22 19:01:42 CEST 2005
Hi all,
I've been working on a Python script that executes an external Windows
program when the user presses a button, and I would like it to stop when
they press another button. To that end, I created a class that
represents the GUI, and there are two methods that are bound to button
events. The following is the code for the two methods:
def startEncode(self,event):
self.newProc = subprocess.Popen(["C:\\Documents and
Settings\Administrator\My Documents\Hendricks\Current
Projects\ITAFeedback\Program\producer.exe"])
#The following line, when uncommented, allows the process to
terminate with no problem
#win32api.TerminateProcess(int(self.newProc._handle),-1)
def stopEncode(self,event):
if self.newProc:
win32api.TerminateProcess(int(self.newProc._handle),-1)
The problem is that I receive the following error when I run the program:
pywintypes.error: (5, 'TerminateProcess', 'Access is denied.')
Now, I'm running as an administrator, so I don't see that as an issue,
and when I call TerminateProcess from within the same method wherein the
process is created, there's no problem. I have seen some email in
various places that mention that this can occur if a new handle is not
created by a separate script, but I assume now that this means that even
from a separate function in the same class, this is not possible. So,
is there some way to communicate the process id correctly between two
methods of a class? I'd really appreciate any help anyone can give me
on this. I've tried many different ways of starting and stopping this
process, and I have not found an adequate solution, as yet. I'm on
Win2k, using Python 2.3 (having installed the subprocess module and the
win32 extensions).
Sean
--
***Please note new email address: shendric at uga.edu***
More information about the Python-win32
mailing list