def _await_socket(self, timeout):
    'Blocks for the nailgun subprocess to bind and emit a listening port in the nailgun\n        stdout.'
    start_time = time.time()
    accumulated_stdout = ''

    def calculate_remaining_time():
        return (time.time() - (start_time + timeout))

    def possibly_raise_timeout(remaining_time):
        if (remaining_time > 0):
            stderr = read_file(self._ng_stderr, binary_mode=True)
            raise self.InitialNailgunConnectTimedOut(timeout=timeout, stdout=accumulated_stdout, stderr=stderr)
    with selectors.PollSelector() as selector, safe_open(self._ng_stdout, 'r') as ng_stdout:
        selector.register(ng_stdout, selectors.EVENT_READ)
        while 1:
            remaining_time = calculate_remaining_time()
            possibly_raise_timeout(remaining_time)
            events = selector.select(timeout=((- 1) * remaining_time))
            if events:
                line = ng_stdout.readline()
                try:
                    return self._NG_PORT_REGEX.match(line).group(1)
                except AttributeError:
                    pass
                accumulated_stdout += line
Blocks for the nailgun subprocess to bind and emit a listening port in the nailgun
stdout.
def _await_socket(self, timeout):
    'Blocks for the nailgun subprocess to bind and emit a listening port in the nailgun\n        stdout.'
    start_time = time.time()
    accumulated_stdout = 

    def calculate_remaining_time():
        return (time.time() - (start_time + timeout))

    def possibly_raise_timeout(remaining_time):
        if (remaining_time > 0):
            stderr = read_file(self._ng_stderr, binary_mode=True)
            raise self.InitialNailgunConnectTimedOut(timeout=timeout, stdout=accumulated_stdout, stderr=stderr)
    with selectors.PollSelector() as selector, safe_open(self._ng_stdout, 'r') as ng_stdout:
        selector.register(ng_stdout, selectors.EVENT_READ)
        while 1:
            remaining_time = calculate_remaining_time()
            possibly_raise_timeout(remaining_time)
            events = selector.select(timeout=((- 1) * remaining_time))
            if events:
                line = ng_stdout.readline()
                try:
                    return self._NG_PORT_REGEX.match(line).group(1)
                except AttributeError:
                    pass
                accumulated_stdout += line