code: def override_print(suppress=False, prefix=None):
      """
      Context manager to override the print to suppress or modify output.
  
      Recommended usage is to call this with suppress=True for all non-primary
      workers, or call with a
      prefix of rank on all workers.
  
      >>> with override_print(prefix="rank{}".format(rank)):
      ...     my_computation()
      :param bool suppress:
          if true, all future print statements are noops.
      :param str prefix:
          if not None, this string is prefixed to all future print statements.
      """
      builtin_print = builtins.print
  
      def new_print(*args, **kwargs):
          if suppress:
              # do nothing
              return
          elif prefix:
              return builtin_print(prefix, *args, **kwargs)
          else:
              # default to normal print
              return builtin_print(*args, **kwargs)
  
      if prefix:
          logging.logger.add_format_prefix(prefix)
      if suppress:
          logging.disable()
  
      # override the print for now
      builtins.print = new_print
      yield
      # bring it back at the end of the context
      builtins.print = builtin_print
  
      if suppress:
          logging.enable()
  
file_path: ParlAI/parlai/utils/distributed.py
imports: import builtins
  import copy
  import os
  import pickle
  import contextlib
  import subprocess
  import socket
  import parlai.utils.logging
label_desc: Use image node_id 5 for calling a global function with example usage: override_print(suppress, prefix) and returns: builtin_print, builtin_print