class_docstr: File-like object, which prints everything written to it, output above the
  current application/prompt. This class is compatible with other file
  objects and can be used as a drop-in replacement for `sys.stdout` or can
  for instance be passed to `logging.StreamHandler`.
  
  The current application, above which we print, is determined by looking
  what application currently runs in the `AppSession` that is active during
  the creation of this instance.
  
  This class can be used as a context manager.
  
  In order to avoid having to repaint the prompt continuously for every
  little write, a short delay of `sleep_between_writes` seconds will be added
  between writes in order to bundle many smaller writes in a short timespan.
class_docstr_tok: ["File-like","object",",","which","prints","everything","written","to","it",",","output","above","the","current","application\/prompt",".","This","class","is","compatible","with","other","file","objects","and","can","be","used","as","a","drop-in","replacement","for","`","sys.stdout","`","or","can","for","instance","be","passed","to","`","logging.StreamHandler","`",".","The","current","application",",","above","which","we","print",",","is","determined","by","looking","what","application","currently","runs","in","the","`","AppSession","`","that","is","active","during","the","creation","of","this","instance",".","This","class","can","be","used","as","a","context","manager",".","In","order","to","avoid","having","to","repaint","the","prompt","continuously","for","every","little","write",",","a","short","delay","of","`","sleep_between_writes","`","seconds","will","be","added","between","writes","in","order","to","bundle","many","smaller","writes","in","a","short","timespan","."]
code: def __init__(
      self,
      sleep_between_writes: float = 0.2,
      raw: bool = False,
  ) -> None:
      self.sleep_between_writes = sleep_between_writes
      self.raw = raw
  
      self._lock = threading.RLock()
      self._buffer: list[str] = []
  
      # Keep track of the curret app session.
      self.app_session = get_app_session()
  
      # See what output is active *right now*. We should do it at this point,
      # before this `StdoutProxy` instance is possibly assigned to `sys.stdout`.
      # Otherwise, if `patch_stdout` is used, and no `Output` instance has
      # been created, then the default output creation code will see this
      # proxy object as `sys.stdout`, and get in a recursive loop trying to
      # access `StdoutProxy.isatty()` which will again retrieve the output.
      self._output: Output = self.app_session.output
  
      # Flush thread
      self._flush_queue: queue.Queue[str | _Done] = queue.Queue()
      self._flush_thread = self._start_write_thread()
      self.closed = False
  
imports: from __future__ import annotations
  import asyncio
  import queue
  import sys
  import threading
  import time
  from contextlib import contextmanager
  from typing import Generator, TextIO, cast
  from .application import get_app_session, run_in_terminal
  from .output import Output
label_desc: Use image node_id 1 to create a new StdoutProxy object  with example: obj = StdoutProxy(sleep_between_writes, raw)