[PATCH 2 of 3 hglib] client: use subprocess.communicate() to shut down server process

Yuya Nishihara yuya at tcha.org
Wed Sep 9 10:35:16 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1441632732 -32400
#      Mon Sep 07 22:32:12 2015 +0900
# Node ID b2c14bdc8741742d3c9d22afaabfdecb8622d7f5
# Parent  37004f608c73fccf1750d42037b37fea3082aa67
client: use subprocess.communicate() to shut down server process

This allows us to get stderr output with no deadlock risk. Also, it should
fix possible deadlock issue at server.wait().

https://docs.python.org/2.7/library/subprocess.html#subprocess.Popen.wait

diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -200,14 +200,13 @@ class hgclient(object):
         Attempting to call any function afterwards that needs to
         communicate with the server will raise a ValueError.
         """
-        return self._close()
+        return self._close()[0]
 
     def _close(self):
-        self.server.stdin.close()
-        self.server.wait()
+        _sout, serr = self.server.communicate()
         ret = self.server.returncode
         self.server = None
-        return ret
+        return ret, serr
 
     def add(self, files=[], dryrun=False, subrepos=False, include=None,
             exclude=None):


More information about the Mercurial-devel mailing list