[PATCH 5 of 9] stdio: catch StdioError in dispatch.run and clean up appropriately

Yuya Nishihara yuya at tcha.org
Wed Apr 12 09:31:30 EDT 2017


On Tue, 11 Apr 2017 10:54:00 -0700, Bryan O'Sullivan wrote:
> On Tue, Apr 11, 2017 at 6:54 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> > > +    if util.safehasattr(req.ui, 'ferr'):
> > > +        if err is not None and err.errno != errno.EPIPE:
> > > +            req.ui.ferr.write('abort: %s\n' % err.strerror)
> > > +        req.ui.ferr.close()
> > > +    sys.exit(status)
> >
> > Is it safe to close stdout and stderr here? IIRC, Python interpreter can
> > somehow crash due to closed stdout/err on Windows.
> 
> The interpreter will crash if the file descriptor backing a file handle is
> closed, but closing the file handle itself isn't a problem.

Thanks for the clarification. We have two file objects attached to the same
stdout fd (see 3a4c0905f357), so fout.close() will be problem. Perhaps, we
only need to do fout.flush() here?


More information about the Mercurial-devel mailing list