Dopo ulteriori indagini, la cosa sembra legata al <a href="http://bugs.python.org/issue1488934">http://bugs.python.org/issue1488934</a><div><br></div><div>in particolare:</div><div><br></div><div>###</div><div><div>$ cat produce.py </div>
<div>import sys</div><div><br></div><div>for x in range(400):</div><div> print 'line '*20</div><div> if 'flush' in sys.argv:</div><div> try:</div><div> sys.stdout.flush()</div><div>
except IOError:</div><div> if 'pass' in sys.argv:</div><div> pass</div><div> else:</div><div> raise</div><div>###</div><div><br></div><div>ha come effetto:</div>
<div><br></div><div><div>$ python produce.py | head -1</div><div>line line line line line line line line line line line line line line line line line line line line </div><div>Traceback (most recent call last):</div><div>
File "produce.py", line 4, in <module></div><div> sys.stdout.write('line '*20+'\n')</div><div>IOError: [Errno 32] Broken pipe</div><div>$ python produce.py | head -1</div><div>line line line line line line line line line line line line line line line line line line line line </div>
<div>close failed in file object destructor:</div><div>Error in sys.excepthook:</div><div><br></div><div>Original exception was: <--------------- random, a volte IOError, a volte errore del distruttore</div><div><br>
</div>
<div>$ python produce.py flush | head -1</div><div>line line line line line line line line line line line line line line line line line line line line </div><div>Traceback (most recent call last):</div><div> File "produce.py", line 7, in <module></div>
<div> sys.stdout.flush()</div><div>IOError: [Errno 32] Broken pipe <------------- "sempre" IOError (ho provato un po' di volte)</div><div><br></div><div><br></div><div>$ python produce.py flush pass | head -1</div>
<div>line line line line line line line line line line line line line line line line line line line line </div><div><br></div><div>sempre OK (idem, per un numero N << infinito di prove)</div></div></div>