from _emerge.SpawnProcess import SpawnProcess
import copy
import io
+import platform
import signal
import sys
import portage
portage.process.spawned_pids.append(pid)
return [pid]
- portage.process._setup_pipes(fd_pipes)
+ # TODO: Find out why PyPy 1.8 with close_fds=True triggers
+ # "[Errno 9] Bad file descriptor" in subprocesses.
+ close_fds = platform.python_implementation() != 'PyPy'
+ portage.process._setup_pipes(fd_pipes, close_fds=close_fds)
# Use default signal handlers in order to avoid problems
# killing subprocesses as reported in bug #353239.
# Distributed under the terms of the GNU General Public License v2
import io
+import platform
import signal
import traceback
return [pid]
os.close(elog_reader_fd)
- portage.process._setup_pipes(fd_pipes)
+
+ # TODO: Find out why PyPy 1.8 with close_fds=True triggers
+ # "[Errno 9] Bad file descriptor" in subprocesses.
+ close_fds = platform.python_implementation() != 'PyPy'
+ portage.process._setup_pipes(fd_pipes, close_fds=close_fds)
# Use default signal handlers since the ones inherited
# from the parent process are irrelevant here.
# And switch to the new process.
os.execve(binary, myargs, env)
-def _setup_pipes(fd_pipes):
+def _setup_pipes(fd_pipes, close_fds=True):
"""Setup pipes for a forked process."""
my_fds = {}
# To protect from cases where direct assignment could
# Then assign them to what they should be.
for fd in my_fds:
os.dup2(my_fds[fd], fd)
- # Then close _all_ fds that haven't been explicitly
- # requested to be kept open.
- for fd in get_open_fds():
- if fd not in my_fds:
- try:
- os.close(fd)
- except OSError:
- pass
+
+ if close_fds:
+ # Then close _all_ fds that haven't been explicitly
+ # requested to be kept open.
+ for fd in get_open_fds():
+ if fd not in my_fds:
+ try:
+ os.close(fd)
+ except OSError:
+ pass
def find_binary(binary):
"""