Mercurial > python-hglib
changeset 62:d1f57f162274
closefds on posix when using subprocess
see added test for a clarification on why this is needed
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Fri, 19 Aug 2011 22:24:14 +0300 |
parents | d0b9215180a4 |
children | 939d1d763bb1 |
files | hglib/__init__.py hglib/client.py hglib/util.py tests/test-hglib.py |
diffstat | 4 files changed, 21 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/hglib/__init__.py Fri Aug 19 22:27:40 2011 +0300 +++ b/hglib/__init__.py Fri Aug 19 22:24:14 2011 +0300 @@ -14,7 +14,8 @@ insecure=insecure) args.insert(0, HGPATH) - proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + close_fds=util.closefds) out, err = proc.communicate() if proc.returncode:
--- a/hglib/client.py Fri Aug 19 22:27:40 2011 +0300 +++ b/hglib/client.py Fri Aug 19 22:24:14 2011 +0300 @@ -24,7 +24,8 @@ env['HGENCODING'] = encoding self.server = subprocess.Popen(args, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, env=env) + stdout=subprocess.PIPE, env=env, + close_fds=util.closefds) self._readhello() self._version = None
--- a/hglib/util.py Fri Aug 19 22:27:40 2011 +0300 +++ b/hglib/util.py Fri Aug 19 22:24:14 2011 +0300 @@ -1,4 +1,6 @@ -import itertools, cStringIO, error +import itertools, cStringIO, error, os + +closefds = os.name == 'posix' def grouper(n, iterable): ''' list(grouper(2, range(4))) -> [(0, 1), (2, 3)] '''
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-hglib.py Fri Aug 19 22:24:14 2011 +0300 @@ -0,0 +1,14 @@ +import common, hglib + +class test_hglib(common.basetest): + def setUp(self): + pass + + def test_close_fds(self): + """ + A weird Python bug that has something to do to inherited file descriptors, + see http://bugs.python.org/issue12786 + """ + common.basetest.setUp(self) + client2 = hglib.open() + self.client.close()