Roger Upole wrote: >Without knowing how the GUI executes the methods (eg in a different >thread,etc) >it's hard to tell what might be happening with the handle between the calls. > > The GUI processes each method when a button event is caught. The methods startEncode() and stopEncode() are in the same class as the GUI. I don't know if that helps, but they are not opened in different threads, at least not intentionally.
>You might be able to open another handle to the process and use that to kill >it. >h=win32api.OpenProcess(True, win32con.PROCESS_TERMINATE, self.newProc.pid) >win32api.TerminateProcess(h,-1) > > That seemed to do the trick. I guess I'm still not clear on how handles work in this instance. Apparently, after the startEncode() method begins and opens the process, the handle automatically closes. Then, when stopEncode is called, the handle is no longer available, although the pid is still available through the Popen instance. Perhaps when a Popen instance is created, there is some kind of temporary handle, since it apparently doesn't have one as a property? I'm not complaining, because it works, it would just be nice to understand exactly why. I'll probably just look through the subprocess module and try to figure it out. Thanks, that helps immensely. Sean > hth > Roger > > >"Sean Q. Hendricks wrote: > > >>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 >> >> > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > > > -- ***Please note new email address: [EMAIL PROTECTED] _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32