bpo-28326: Fixes multiprocessing.Process depends on sys.stdout being open by tiagoantao · Pull Request #1410 · python/cpython (original) (raw)

Either change this to
if sys.stdout is not None and not sys.stdout.closed:

or change the entire statement to

        try:
            sys.stdout.flush()
        except (AttributeError, ValueError):  # stdout None or closed.
            pass

and the equivalent for stderr. I slightly prefer the latter (these exceptions should be rare), but if Antoine expresses a preference for the former, use that.