[PATCH 1 of 6] util: add iterfile to workaround a fileobj.__iter__ issue with EINTR

Jun Wu quark at fb.com
Mon Nov 14 18:58:52 EST 2016


Excerpts from Gregory Szorc's message of 2016-11-14 15:49:06 -0800:
> > without a incorrect errno - could be 0 - thus "IOError: [Errno 0] Error".
   ^^^^^^^^^^^^^^^^^^^ this should be "with an incorrect". Sorry :'(

> > The only user of "readahead" is "readahead_get_line_skip".
> > The only user of "readahead_get_line_skip" is "file_iternext", aka.
> > "fileobj.__iter__", which should be avoided.
> >
> > There are multiple places where the pattern "for x in fp" is used. This
> > patch adds a "iterfile" method in "util.py" so we can migrate our code from
> > "for x in fp" to "fox x in util.iterfile(fp)".
> >
> 
> Bleh. Is this bug reported upstream? (Not that it helps us much.)

I guess no? I'll report it tomorrow. Python 3 seems to be unrelated as the
old code seems to have been largely rewritten.

> This seems like a pretty trivial workaround. So LGTM.
> 
> >
> > diff --git a/mercurial/util.py b/mercurial/util.py
> > --- a/mercurial/util.py
> > +++ b/mercurial/util.py
> > @@ -2191,4 +2191,9 @@ def wrap(line, width, initindent='', han
> >      return wrapper.fill(line).encode(encoding.encoding)
> >
> > +def iterfile(fp):
> > +    """like fp.__iter__ but does not have issues with EINTR. Python
> > 2.7.12 is
> > +    known to have such issues."""
> > +    return iter(fp.readline, '')
> > +
> >  def iterlines(iterator):
> >      for chunk in iterator:
> > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel 
> >


More information about the Mercurial-devel mailing list