Don't raise an exception if sys.stdout is replaced with a stub. See GH-788.