Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] portage.process.spawn: default close_fds=False (bug 648432)
Date: Wed, 21 Feb 2018 23:28:33
Message-Id: 20180221232743.3786-1-zmedico@gentoo.org
1 For python3.4 and later, default to close_fds=False, since file
2 descriptors are non-inheritable by default due to PEP 446. This solves
3 a performance problem on systems like FreeBSD, where our get_open_fds
4 function returns all possible file descriptor values (including those
5 that are not open).
6
7 Bug: https://bugs.gentoo.org/648432
8 See: https://www.python.org/dev/peps/pep-0446/
9 ---
10 pym/portage/process.py | 6 ++++--
11 1 file changed, 4 insertions(+), 2 deletions(-)
12
13 diff --git a/pym/portage/process.py b/pym/portage/process.py
14 index bc4efb5fe..4d96f156e 100644
15 --- a/pym/portage/process.py
16 +++ b/pym/portage/process.py
17 @@ -196,7 +196,8 @@ def cleanup():
18
19 def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
20 uid=None, gid=None, groups=None, umask=None, logfile=None,
21 - path_lookup=True, pre_exec=None, close_fds=True, unshare_net=False,
22 + path_lookup=True, pre_exec=None,
23 + close_fds=(sys.version_info < (3, 4)), unshare_net=False,
24 unshare_ipc=False, cgroup=None):
25 """
26 Spawns a given command.
27 @@ -228,7 +229,8 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
28 @param pre_exec: A function to be called with no arguments just prior to the exec call.
29 @type pre_exec: callable
30 @param close_fds: If True, then close all file descriptors except those
31 - referenced by fd_pipes (default is True).
32 + referenced by fd_pipes (default is True for python3.3 and earlier, and False for
33 + python3.4 and later due to non-inheritable file descriptor behavior from PEP 446).
34 @type close_fds: Boolean
35 @param unshare_net: If True, networking will be unshared from the spawned process
36 @type unshare_net: Boolean
37 --
38 2.13.6

Replies