[issue12540] "Restart Shell" command leaves pythonw.exe processes running

Eli Bendersky report at bugs.python.org
Fri Jul 29 08:04:14 CEST 2011


Eli Bendersky <eliben at gmail.com> added the comment:

Terry,

""" When I tried the same fix in idlelib/PyShell.py, adding 'import subprocess' and changing
        self.rpcpid = os.spawnv(os.P_NOWAIT, sys.executable, args)
to
        self.rpcpid = subprocess.Popen(args).pid
(args begins with sys.executable) IDLE failed to start. The only evidence that it had been invoked was a brief (1/4 second?) appearance of 1 pythonw process in task manager. On a subsequent tries, without touching the file, I do not see even that. Is there any obvious mistake in the above? """

No, when I do the same, things seem to go fine. No zombie is left running after IDLE is closed, and even "Restart shell" works without leaving a zombie.

Maybe you had other modifications in your idlelib sources? 

Anyway, this wouldn't be a complete fix, because in:

    def unix_terminate(self):
        "UNIX: make sure subprocess is terminated and collect status"
        if hasattr(os, 'kill'):
            try:
                os.kill(self.rpcpid, SIGTERM)
            except OSError:
                # process already terminated:
                return
            else:
                try:
                    os.waitpid(self.rpcpid, 0)
                except OSError:
                    return

os.waitpid on Windows also expects a process handle, not pid. 

I think the complete solution, in addition to replacing os.spawnv by subprocess.Popen, would be to use Popen.kill and then Popen.wait instead of os.kill and then os.wait in the code above. This would require keeping the Popen object somewhere in self.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12540>
_______________________________________


More information about the Python-bugs-list mailing list