class_docstr: A file like object that publishes the stream to a 0MQ PUB socket.
  
  Output is handed off to an IO Thread
class_docstr_tok: ["A","file","like","object","that","publishes","the","stream","to","a","0MQ","PUB","socket",".","Output","is","handed","off","to","an","IO","Thread"]
docstr: Parameters
  ----------
  session : object
      the session object
  pub_thread : threading.Thread
      the publication thread
  name : str {'stderr', 'stdout'}
      the name of the standard stream to replace
  pipe : object
      the pip object
  echo : bool
      whether to echo output
  watchfd : bool (default, True)
      Watch the file descriptor corresponding to the replaced stream.
      This is useful if you know some underlying code will write directly
      the file descriptor by its number. It will spawn a watching thread,
      that will swap the give file descriptor for a pipe, read from the
      pipe, and insert this into the current Stream.
  isatty : bool (default, False)
      Indication of whether this stream has terminal capabilities (e.g. can handle colors)
code: def __init__(
      self,
      session,
      pub_thread,
      name,
      pipe=None,
      echo=None,
      *,
      watchfd=True,
      isatty=False,
  ):
      """
      Parameters
      ----------
      session : object
          the session object
      pub_thread : threading.Thread
          the publication thread
      name : str {'stderr', 'stdout'}
          the name of the standard stream to replace
      pipe : object
          the pip object
      echo : bool
          whether to echo output
      watchfd : bool (default, True)
          Watch the file descriptor corresponding to the replaced stream.
          This is useful if you know some underlying code will write directly
          the file descriptor by its number. It will spawn a watching thread,
          that will swap the give file descriptor for a pipe, read from the
          pipe, and insert this into the current Stream.
      isatty : bool (default, False)
          Indication of whether this stream has terminal capabilities (e.g. can handle colors)
  
      """
      if pipe is not None:
          warnings.warn(
              "pipe argument to OutStream is deprecated and ignored since ipykernel 4.2.3.",
              DeprecationWarning,
              stacklevel=2,
          )
      # This is necessary for compatibility with Python built-in streams
      self.session = session
      if not isinstance(pub_thread, IOPubThread):
          # Backward-compat: given socket, not thread. Wrap in a thread.
          warnings.warn(
              "Since IPykernel 4.3, OutStream should be created with "
              "IOPubThread, not %r" % pub_thread,
              DeprecationWarning,
              stacklevel=2,
          )
          pub_thread = IOPubThread(pub_thread)
          pub_thread.start()
      self.pub_thread = pub_thread
      self.name = name
      self.topic = b"stream." + name.encode()
      self.parent_header = {}
      self._master_pid = os.getpid()
      self._flush_pending = False
      self._subprocess_flush_pending = False
      self._io_loop = pub_thread.io_loop
      self._buffer_lock = threading.RLock()
      self._buffer = StringIO()
      self.echo = None
      self._isatty = bool(isatty)
      self._should_watch = False
      self._local = local()
  
      if (
          watchfd
          and (
              (
                  sys.platform.startswith("linux")
                  or sys.platform.startswith("darwin")
              )
              # Pytest set its own capture. Don't redirect from within pytest.
              and ("PYTEST_CURRENT_TEST" not in os.environ)
          )
          # allow forcing watchfd (mainly for tests)
          or watchfd == "force"
      ):
          self._should_watch = True
          self._setup_stream_redirects(name)
  
      if echo:
          if hasattr(echo, "read") and hasattr(echo, "write"):
              # make sure we aren't trying to echo on the FD we're watching!
              # that would cause an infinite loop, always echoing on itself
              if self._should_watch:
                  try:
                      echo_fd = echo.fileno()
                  except Exception:
                      echo_fd = None
  
                  if (
                      echo_fd is not None
                      and echo_fd == self._original_stdstream_fd
                  ):
                      # echo on the _copy_ we made during
                      # this is the actual terminal FD now
                      echo = io.TextIOWrapper(
                          io.FileIO(
                              self._original_stdstream_copy,
                              "w",
                          )
                      )
              self.echo = echo
          else:
              msg = "echo argument must be a file-like object"
              raise ValueError(msg)
  
imports: import asyncio
  import atexit
  import io
  import os
  import sys
  import threading
  import traceback
  import warnings
  from binascii import b2a_hex
  from collections import deque
  from io import StringIO, TextIOBase
  from threading import local
  from typing import Any, Callable, Deque, Dict, Optional
  import zmq
  from jupyter_client.session import extract_header
  from tornado.ioloop import IOLoop
  from zmq.eventloop.zmqstream import ZMQStream
label_desc: Use image node_id 3 to create a new OutStream object from inherited base classes: TextIOBase with example: obj = OutStream(session, pub_thread, name, pipe, echo)