def stdin_thread_main()

in nailgun-client/py/ng.py [0:0]


def stdin_thread_main(conn):
    """
    Stdin thread reading worker function
    If stdin is available, read it to internal buffer and send to server
    """
    try:
        eof = False
        while True:
            # wait for signal to read new line from stdin or shutdown
            # we  do not start reading from stdin before server actually requests that
            with conn.stdin_condition:
                if conn.shutdown_event.is_set():
                    return
                conn.stdin_condition.wait()
                if conn.shutdown_event.is_set():
                    return

            if not conn.stdin or eof:
                conn._send_chunk(buf, CHUNKTYPE_STDIN_EOF)
                continue

            buf = conn.stdin.readline()
            if buf == "":
                eof = True
                conn._send_chunk(buf, CHUNKTYPE_STDIN_EOF)
                continue
            conn._send_chunk(buf, CHUNKTYPE_STDIN)
    except Exception as e:
        # save exception to rethrow on main thread
        with conn.error_lock:
            conn.error = e
            conn.error_traceback = sys.exc_info()[2]
        conn.shutdown_event.set()