summaryrefslogtreecommitdiffstats
path: root/pym/_emerge/SpawnProcess.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2013-01-15 12:09:21 -0800
committerZac Medico <zmedico@gentoo.org>2013-01-15 12:09:21 -0800
commitdbe26095102cbdc6d5bef3509f05bc7b42c418cc (patch)
treefbdc5d18ff9fa33dc7b69fdb6c173312cb4507a8 /pym/_emerge/SpawnProcess.py
parent7c624515d0bb106c8a468addff5df153cebf31fc (diff)
downloadportage-dbe26095102cbdc6d5bef3509f05bc7b42c418cc.tar.gz
portage-dbe26095102cbdc6d5bef3509f05bc7b42c418cc.tar.bz2
portage-dbe26095102cbdc6d5bef3509f05bc7b42c418cc.zip
SpawnProcess: improve dummy pipe allocation logic
By using allocated file descriptors for keys in fd_pipes, we naturally avoid interference with callers such as FileDigester and MergeProcess. See the _setup_pipes docstring for more benefits of this allocation approach.
Diffstat (limited to 'pym/_emerge/SpawnProcess.py')
-rw-r--r--pym/_emerge/SpawnProcess.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/pym/_emerge/SpawnProcess.py b/pym/_emerge/SpawnProcess.py
index 9c754add5..ebba7d3d4 100644
--- a/pym/_emerge/SpawnProcess.py
+++ b/pym/_emerge/SpawnProcess.py
@@ -70,23 +70,20 @@ class SpawnProcess(SubProcess):
fd_pipes_orig = fd_pipes.copy()
- if log_file_path is not None:
+ if log_file_path is not None or self.background:
fd_pipes[1] = slave_fd
fd_pipes[2] = slave_fd
else:
- # Create a dummy pipe so the scheduler can monitor
- # the process from inside a poll() loop. Ensure that
- # it doesn't interfere with a random fd that's already
- # in fd_pipes though (as least FileDigester can pass
- # in a random fd returned from os.pipe()).
- unique_dummy_fd = self._dummy_pipe_fd
- while unique_dummy_fd in fd_pipes:
- unique_dummy_fd += 1
- fd_pipes[unique_dummy_fd] = slave_fd
- if self.background:
- fd_pipes[1] = slave_fd
- fd_pipes[2] = slave_fd
+ # Create a dummy pipe that PipeLogger uses to efficiently
+ # monitors for process exit by listening for the EOF event.
+ # Re-use of the allocated fd number for the key in fd_pipes
+ # guarantees that the keys will not collide for similarly
+ # allocated pipes which are used by callers such as
+ # FileDigester and MergeProcess. See the _setup_pipes
+ # docstring for more benefits of this allocation approach.
+ self._dummy_pipe_fd = slave_fd
+ fd_pipes[slave_fd] = slave_fd
kwargs = {}
for k in self._spawn_kwarg_names: