Dopo ulteriori indagini, la cosa sembra legata al
http://bugs.python.org/issue1488934

in particolare:

###
$ cat produce.py
import sys

for x in range(400):
    print 'line '*20
    if 'flush' in sys.argv:
        try:
            sys.stdout.flush()
        except IOError:
            if 'pass' in sys.argv:
                pass
            else:
                raise
###

ha come effetto:

$ python produce.py | head -1
line line line line line line line line line line line line line line line
line line line line line
Traceback (most recent call last):
  File "produce.py", line 4, in <module>
    sys.stdout.write('line '*20+'\n')
IOError: [Errno 32] Broken pipe
$ python produce.py | head -1
line line line line line line line line line line line line line line line
line line line line line
close failed in file object destructor:
Error in sys.excepthook:

Original exception was:  <--------------- random, a volte IOError, a volte
errore del distruttore

$ python produce.py flush | head -1
line line line line line line line line line line line line line line line
line line line line line
Traceback (most recent call last):
  File "produce.py", line 7, in <module>
    sys.stdout.flush()
IOError: [Errno 32] Broken pipe   <------------- "sempre" IOError (ho
provato un po' di volte)


$ python produce.py flush pass | head -1
line line line line line line line line line line line line line line line
line line line line line

sempre OK (idem, per un numero N << infinito di prove)
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a