class_docstr: Allowed patching a stream into the logger.
  Used for capturing and logging stdin and stderr when running in development mode pseudo worker.
class_docstr_tok: ["Allowed","patching","a","stream","into","the","logger",".","Used","for","capturing","and","logging","stdin","and","stderr","when","running","in","development","mode","pseudo","worker","."]
code: def write(self, message):
      # make sure that we do not end up in infinite loop (i.e. log.console ends up calling us)
      if (
          self._log
          and not PrintPatchLogger.recursion_protect_lock._is_owned()
      ):  # noqa
          try:
              # make sure we flush from time to time on \r
              self._test_lr_flush()
  
              self.lock.acquire()
              # noinspection PyBroadException
              try:
                  with PrintPatchLogger.recursion_protect_lock:
                      if hasattr(self._terminal, "_original_write"):
                          self._terminal._original_write(
                              message
                          )  # noqa
                      else:
                          self._terminal.write(message)
              except Exception:
                  pass
  
              do_flush = "\n" in message
              # check for CR character
              do_cr = "\r" in message
              # check for "Escape Arrow-Up" character (tqdm's way of clearing a line)
              if "\x1b[A" in message:
                  do_cr = True
                  # replace it with \r so it is more standard
                  message = message.replace("\x1b[A", "\r")
  
              self._cur_line += message
  
              if (
                  not do_flush
                  and do_cr
                  and PrintPatchLogger.cr_flush_period
                  and self._force_lf_flush
              ):
                  self._cur_line += "\n"
                  do_flush = True
  
              if (
                  not do_flush
                  and (PrintPatchLogger.cr_flush_period or not do_cr)
              ) or not message:
                  return
  
              if PrintPatchLogger.cr_flush_period and self._cur_line:
                  self._cur_line = "\n".join(
                      line.split("\r")[-1]
                      for line in self._cur_line.split("\n")
                  )
  
              last_lf = self._cur_line.rindex(
                  "\n" if do_flush else "\r"
              )
              next_line = self._cur_line[last_lf + 1 :]
              cur_line = self._cur_line[: last_lf + 1].rstrip()
              self._cur_line = next_line
          finally:
              self.lock.release()
  
          if cur_line:
              self._force_lf_flush = False
              with PrintPatchLogger.recursion_protect_lock:
                  # noinspection PyBroadException
                  try:
                      if self._log:
                          # noinspection PyProtectedMember
                          self._log._console(
                              cur_line,
                              level=self._log_level,
                              omit_console=True,
                          )
                  except Exception:
                      # what can we do, nothing
                      pass
      else:
          # noinspection PyBroadException
          try:
              if hasattr(self._terminal, "_original_write"):
                  self._terminal._original_write(message)  # noqa
              else:
                  self._terminal.write(message)
          except Exception:
              pass
  
imports: import logging
  import sys
  from time import time
  from ..binding.frameworks import _patched_call
  from ..config import running_remotely, config, DEBUG_SIMULATE_REMOTE_TASK
  from ..utilities.process.mp import ForkSafeRLock
label_desc: Use image node_id 2 for calling the PrintPatchLogger obj's underlying member method code with example usage: obj.write(message) without return types