# HG changeset patch # User Idan Kamara # Date 1313781854 -10800 # Node ID d1f57f162274478090a7de2b3be2dc940cdf3501 # Parent d0b9215180a46cd1952aaa4e24e3e703b927ce67 closefds on posix when using subprocess see added test for a clarification on why this is needed diff -r d0b9215180a4 -r d1f57f162274 hglib/__init__.py --- 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: diff -r d0b9215180a4 -r d1f57f162274 hglib/client.py --- 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 diff -r d0b9215180a4 -r d1f57f162274 hglib/util.py --- 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)] ''' diff -r d0b9215180a4 -r d1f57f162274 tests/test-hglib.py --- /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()