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"]
code: def write(self, string):
      if self.echo is not None:
          try:
              self.echo.write(string)
          except OSError as e:
              if self.echo is not sys.__stderr__:
                  print(
                      "Write failed: {}".format(e), file=sys.__stderr__
                  )
  
      if self.pub_thread is None:
          raise ValueError("I/O operation on closed file")
      else:
          # Make sure that we're handling unicode
          if not isinstance(string, unicode_type):
              string = string.decode(self.encoding, "replace")
  
          is_child = not self._is_master_process()
          # only touch the buffer in the IO thread to avoid races
          self.pub_thread.schedule(lambda: self._buffer.write(string))
          if is_child:
              # newlines imply flush in subprocesses
              # mp.Pool cannot be trusted to flush promptly (or ever),
              # and this helps.
              if "\n" in string:
                  self.flush()
          else:
              self._schedule_flush()
  
imports: from __future__ import print_function
  import atexit
  from binascii import b2a_hex
  from collections import deque
  import os
  import sys
  import threading
  import warnings
  from io import StringIO, TextIOBase
  import zmq
  from zmq.eventloop.ioloop import IOLoop
  from zmq.eventloop.zmqstream import ZMQStream
  from jupyter_client.session import extract_header
  from ipython_genutils import py3compat
  from ipython_genutils.py3compat import unicode_type
label_desc: Use image node_id 9 for calling the OutStream obj's underlying member method code with example usage: obj.write(string) without return types