I can get rid of the shell=1 using subprocess.Popen(["python.exe", "C:\\Python27\\Scripts\\test.py"]). This also works fine using debug mode. I can kill it via os.kill() or Popen.send_signal().
It also runs fine via "net start". But when I stop it via "net stop", it gives me the following error: ok.kill(self.pid, signal.CTRL_BREAK_EVENT) WindowsError: (6, 'The handle is invalid') I have verified that Popen.pid matches the PID of python.exe in tasklist. The python docs say that on windows, os.kill() also takes a handle. I tried passing it Popen._handle (and int(Popen._handle)), but it still says the handle is invalid. Any idea why the handle would be invalid? Patrick On Tue, Jun 18, 2013 at 11:13 PM, Mark Hammond <skippy.hamm...@gmail.com>wrote: > The other solutions I can think of are likely heavier and harder than > arranging to spawn the child without shell=1 - so I'd suggest tackling that. > > Or *maybe* - you could do something like spawning a thread in the child > process to read from stdin - that's likely to block until the cmd.exe > parent is killed, in which case the read would return with an error - at > which point the child could terminate itself... > > Mark > > > On 19/06/2013 7:51 AM, Patrick Tisdale wrote: > >> Hello list, >> I have written a test script to run as a service. The service starts up >> properly, and spawns a subprocess (called test.py) using >> subprocess.Popen. However, I am having no luck killing the subprocess >> when I stop the service. I am using os.kill() >> >> It works fine when running pythonservice.exe in debug mode. But when I >> start it using "net start" the subprocess.Popen.pid matches the "cmd" >> that it spawns (due to shell=True, I suppose). I have tried it without >> shell=True, but can't get the script to run without it. >> >> >> The test script is a simple script that periodically writes to a file. >> The script that I actually need to make work is a twisted twistd (.tac) >> file, which will have multiple TCP connections open, and I need to be >> able to close those connections before it exits. >> >> Any ideas on what I'm missing? >> >> Thanks, >> Patrick Tisdale >> >> >> ______________________________**_________________ >> python-win32 mailing list >> python-win32@python.org >> http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32> >> >> >
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32