Get a pipe for paging output.

If no active pager process exists, fork one and return its input pipe.
484605
private function getPipe()
    {
        if (!isset($this->pipe) || !isset($this->proc)) {
            $desc = [['pipe', 'r'], $this->stream, \fopen('php://stderr', 'w')];
            $this->proc = \proc_open($this->cmd, $desc, $pipes);

            if (!\is_resource($this->proc)) {
                throw new \RuntimeException('Error opening output stream');
            }

            $this->pipe = $pipes[0];
        }

        return $this->pipe;
    }
723127
def wait(self) -> None:
        """"""
        if self._out_thread.is_alive():
            self._out_thread.join()
        if self._err_thread.is_alive():
            self._err_thread.join()

        # Handle case where the process ended before the last read could be done.
        # This will return None for the streams that weren't pipes.
        out, err = self._proc.communicate()

        if out:
            self._write_bytes(self._stdout, out)
        if err:
            self._write_bytes(self._stderr, err)
910971
def _get_result(future, pipe, timeout):
    """"""
    counter = count(step=SLEEP_UNIT)

    try:
        while not pipe.poll(SLEEP_UNIT):
            if timeout is not None and next(counter) >= timeout:
                return TimeoutError('Task Timeout', timeout)
            elif future.cancelled():
                return CancelledError()

        return pipe.recv()
    except (EOFError, OSError):
        return ProcessExpired('Abnormal termination')
    except Exception as error:
        return error
221713
def get_process_triple():
    
    with ffi.OutputString() as out:
        ffi.lib.LLVMPY_GetProcessTriple(out)
        return str(out)
27471
def pipe_to_process(self, payload):
        """"""
        message = payload['input']
        key = payload['key']
        if not self.process_handler.is_running(key):
            return {'message': 'No running process for this key',
                    'status': 'error'}
        self.process_handler.send_to_process(message, key)
        return {'message': 'Message sent',
                'status': 'success'}
1306871
public static InputStream routeStreamThroughProcess(final Process p, final InputStream origin, final boolean closeInput)
	{
		InputStream processSTDOUT = p.getInputStream();
		OutputStream processSTDIN = p.getOutputStream();

		// Kick off a background copy to the process
		StreamUtil.doBackgroundCopy(origin, processSTDIN, DUMMY_MONITOR, true, closeInput);

		return processSTDOUT;
	}
394735
def get(self, limit=None, page=None):
        
        has_more = False
        self.bounds.paginate = True
        limit_paginate, offset = self.bounds.get(limit, page)
        self.default_val = []
        results = self._query('get')

        if limit_paginate:
            self.bounds.paginate = False
            if len(results) == limit_paginate:
                has_more = True
                results.pop(-1)

        it = ResultsIterator(results, orm_class=self.orm_class, has_more=has_more, query=self)
        return self.iterator_class(it)
490486
def pager_redirect(desc, *, pagercmd=None, istty=None, file=None,
                   substitutions=None):
    
    global _pager_active
    if file is None:
        file = sys.stdout
    if not pagercmd or not file.isatty() or _pager_active:
        yield
        return
    subs = {"desc": desc}
    if substitutions is not None:
        subs.update(substitutions)
    pagercmd = pagercmd.format(**subs)
    with tty_restoration():
        p = pager_process(pagercmd)
        if istty is None:
            p.stdin.isatty = file.isatty
        else:
            p.stdin.isatty = lambda: istty
        stdout_save = sys.stdout
        sys.stdout = p.stdin
        _pager_active = True
        try:
            yield
        finally:
            _pager_active = False
            sys.stdout = stdout_save
            try:
                p.stdin.close()
            except BrokenPipeError:
                pass
            while p.poll() is None:
                try:
                    p.wait()
                except KeyboardInterrupt:
                    pass
845147
def _read_incoming(self):
        """"""
        fileno = self.proc.stdout.fileno()
        while 1:
            buf = b''
            try:
                buf = os.read(fileno, 1024)
            except OSError as e:
                self._log(e, 'read')

            if not buf:
                # This indicates we have reached EOF
                self._read_queue.put(None)
                return

            self._read_queue.put(buf)
949870
def repeater(pipe, how_many=2):
    '''  '''
    r = range(how_many)
    for i in pipe:
        for _ in r:
            yield i
177618
def show_in_pager(self, strng, *args, **kwargs):
    
    # On PyDev we just output the string, there are scroll bars in the console
    # to handle "paging". This is the same behaviour as when TERM==dump (see
    # page.py)
    # for compatibility with mime-bundle form:
    if isinstance(strng, dict):
        strng = strng.get('text/plain', strng)
    print(strng)
507888
def pager(text, color=None):
    """"""
    stdout = _default_text_stdout()
    if not isatty(sys.stdin) or not isatty(stdout):
        return _nullpager(stdout, text, color)
    if 'PAGER' in os.environ:
        if WIN:
            return _tempfilepager(text, os.environ['PAGER'], color)
        return _pipepager(text, os.environ['PAGER'], color)
    if os.environ.get('TERM') in ('dumb', 'emacs'):
        return _nullpager(stdout, text, color)
    if WIN or sys.platform.startswith('os2'):
        return _tempfilepager(text, 'more <', color)
    if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
        return _pipepager(text, 'less', color)

    import tempfile
    fd, filename = tempfile.mkstemp()
    os.close(fd)
    try:
        if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:
            return _pipepager(text, 'more', color)
        return _nullpager(stdout, text, color)
    finally:
        os.unlink(filename)
768665
private function outputBufferingHandlerMiddleware()
    {
        return function (ServerRequestInterface $request, DelegateInterface $delegate) {
            ob_start();
            try {
                $response = $delegate->process($request);
            } finally {
                ob_end_clean();
            }
            return $response;
        };
    }
1237252
def get(self, loop=None):
        """"""
        self._clear_done_waiters()
        if not self._waiters:
            # If something is available directly, we can avoid going back to
            # the scheduler
            try:
                heap = self.get_nowait()
            except spead2.Empty:
                pass
            else:
                # Give the event loop a chance to run. This ensures that a
                # heap-processing loop cannot live-lock the event loop.
                yield
                raise Return(heap)

        if loop is None:
            loop = self._loop
        waiter = trollius.Future(loop=loop)
        self._waiters.append(waiter)
        self._start_listening()
        heap = (yield From(waiter)).pop()
        raise Return(heap)
859139
def get_paged_request(url, headers=None, **params):
    """"""
    results = []
    params.setdefault("per_page", 100)
    while True:
        if '?' in url:
            params = None
            print("fetching %s" % url, file=sys.stderr)
        else:
            print("fetching %s with %s" % (url, params), file=sys.stderr)
        response = requests.get(url, headers=headers, params=params)
        response.raise_for_status()
        results.extend(response.json())
        if 'next' in response.links:
            url = response.links['next']['url']
        else:
            break
    return results
356552
def get_pid(rundir, process_type=PROCESS_TYPE, name=None):
    
    pidPath = get_pidpath(rundir, process_type, name)
    log.log('run', 'pidfile for %s %s is %s' % (process_type, name, pidPath))

    if not os.path.exists(pidPath):
        return

    pidFile = open(pidPath, 'r')
    pid = pidFile.readline()
    pidFile.close()
    if not pid or int(pid) == 0:
        return

    return int(pid)
473940
def get_stdin_pid(cached_result=None):
    """"""
    if cached_result is None:
        try:
            tasks = os.listdir('/proc/self/task')
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise
            cached_result = os.getpid()
        else:
            tasks.remove(str(os.getpid()))
            assert len(tasks) == 1
            cached_result = int(tasks[0])
    return cached_result