[PATCH] ui: ignore EIO in write_err

Mads Kiilerich mads at kiilerich.com
Wed Jun 16 04:44:37 CDT 2010


On 06/16/2010 09:20 AM, Dirkjan Ochtman wrote:
> On Wed, Jun 16, 2010 at 00:24, Mads Kiilerich<mads at kiilerich.com>  wrote:
>> diff --git a/mercurial/ui.py b/mercurial/ui.py
>> --- a/mercurial/ui.py
>> +++ b/mercurial/ui.py
>> @@ -369,7 +369,7 @@
>>              if not getattr(sys.stderr, 'closed', False):
>>                  sys.stderr.flush()
>>          except IOError, inst:
>> -            if inst.errno != errno.EPIPE:
>> +            if inst.errno not in [errno.EPIPE, errno.EIO]:
>>                  raise
>>
>>      def flush(self):
>
> Nit: this feels like it should be a tuple, not a list.

I feel like lists are more like "columns" where all the items have the 
same type, while tuples are more like "rows" where the items have 
different types and different semantics depending on their position. In 
this case it _is_ a list, not a tuple. We could use tuples to implement 
immutable lists, but I prefer the clarity of using lists for lists.

grep '\[[^[]*,[^[]*\]' mercurial/*.py|grep -v '\<for\>.*\<in\>'
shows some other examples where lists are used for lists.

Tuples might be faster to construct (2-4 times?) in Cpython, but 
wouldn't it be a premature optimization to optimize for that?

I will resend if other prefers tuples too ;-)


A better question could however be if there is any reason why we 
shouldn't ignore all IOErrors in write_err - that would avoid this 
discussion ,-)

/Mads


$ python -m timeit '[1,2]'
1000000 loops, best of 3: 0.327 usec per loop

$ python -m timeit '(1,2)'
10000000 loops, best of 3: 0.0754 usec per loop

$ python -m timeit -s 'a=[1,2]' 'a[:]'
1000000 loops, best of 3: 0.366 usec per loop

$ python -m timeit -s 'a=(1,2)' 'a[:]'
10000000 loops, best of 3: 0.156 usec per loop



More information about the Mercurial-devel mailing list