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

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 9, 2015, 3:35 p.m.
Message ID <b2c14bdc8741742d3c9d.1441812916@mimosa>
Download mbox | patch
Permalink /patch/10439/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 9, 2015, 3:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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

Patch

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):