From 4d1eb74f1ccce825c7f3fdbb947d278fd61b12b5 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 17 Jul 2008 04:20:12 +0000 Subject: [PATCH] When SpawnProcess._start() spawns a process in the background, use /dev/null so that any attempts to read from stdin will immediately return EOF instead of blocking indefinitely. TODO: Use job control functions like tcsetpgrp() to control access to stdin. svn path=/main/trunk/; revision=11093 --- pym/_emerge/__init__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 1373d3abb..13df0d8f5 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -2045,11 +2045,21 @@ class SpawnProcess(SubProcess): fcntl.fcntl(master_fd, fcntl.F_SETFL, fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK) + null_input = None + fd_pipes_orig = fd_pipes.copy() + if self.background: + # TODO: Use job control functions like tcsetpgrp() to control + # access to stdin. Until then, use /dev/null so that any + # attempts to read from stdin will immediately return EOF + # instead of blocking indefinitely. + null_input = open('/dev/null', 'rb') + fd_pipes[0] = null_input.fileno() + else: + fd_pipes[0] = fd_pipes_orig[0] + files.process = os.fdopen(master_fd, 'r') if logfile is not None: - fd_pipes_orig = fd_pipes.copy() - fd_pipes[0] = fd_pipes_orig[0] fd_pipes[1] = slave_fd fd_pipes[2] = slave_fd @@ -2086,6 +2096,8 @@ class SpawnProcess(SubProcess): retval = self._spawn(self.args, **kwargs) os.close(slave_fd) + if null_input is not None: + null_input.close() if isinstance(retval, int): # spawn failed -- 2.26.2