code: def ignore_broken_pipe():
      
      for f in sys.stdin, sys.stdout, sys.stderr:
          try:
              f.close()
          except BrokenPipeError:
              pass
docs: If a shellish program has redirected stdio it is subject to erroneous
      "ignored" exceptions during the interpretor shutdown. This essentially
      beats the interpretor to the punch by closing them early and ignoring any
      broken pipe exceptions.