# HG changeset patch # User Durham Goode # Date 2013-03-09 00:59:36 # Node ID 9baf4330d88f81475cadcfd2041fc100f6cf201f # Parent 6aca4d1c744ed8f6c1305525ded7590abaa72d06 sshpeer: store subprocess so it cleans up correctly When running 'hg pull --rebase', I was seeing this exception 100% of the time as the python process was closing down: Exception TypeError: TypeError("'NoneType' object is not callable",) in > ignored By storing the subprocess on the sshpeer, the subprocess seems to clean up correctly, and I no longer see the exception. I have no idea why this actually works, but I get a 0% repro if I store the subprocess in self.subprocess, and a 100% repro if I store None in self.subprocess. Possibly related to issue 2240. diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py --- a/mercurial/sshpeer.py +++ b/mercurial/sshpeer.py @@ -70,7 +70,10 @@ class sshpeer(wireproto.wirepeer): (_serverquote(remotecmd), _serverquote(self.path)))) ui.note(_('running %s\n') % cmd) cmd = util.quotecommand(cmd) - self.pipeo, self.pipei, self.pipee = util.popen3(cmd) + + # while self.subprocess isn't used, having it allows the subprocess to + # to clean up correctly later + self.pipeo, self.pipei, self.pipee, self.subprocess = util.popen4(cmd) # skip any noise generated by remote shell self._callstream("hello") diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -129,13 +129,17 @@ def popen2(cmd, env=None, newlines=False return p.stdin, p.stdout def popen3(cmd, env=None, newlines=False): + stdin, stdout, stderr, p = popen4(cmd, env, newlines) + return stdin, stdout, stderr + +def popen4(cmd, env=None, newlines=False): p = subprocess.Popen(cmd, shell=True, bufsize=-1, close_fds=closefds, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=newlines, env=env) - return p.stdin, p.stdout, p.stderr + return p.stdin, p.stdout, p.stderr, p def version(): """Return version information if available."""