Ian Kelly wrote: > On Thu, Mar 10, 2016 at 2:33 PM, Fillmore <fillmore_rem...@hotmail.com> > wrote: >> >> when I put a Python script in pipe with other commands, it will refuse to >> let go silently. Any way I can avoid this? > > What is your script doing? I don't see this problem. > > ikelly@queso:~ $ cat somescript.py > import sys > > for i in range(20): > sys.stdout.write('line %d\n' % i) > ikelly@queso:~ $ python somescript.py | head -5 > line 0 > line 1 > line 2 > line 3 > line 4 > ikelly@queso:~ $ python3 somescript.py | head -5 > line 0 > line 1 > line 2 > line 3 > line 4
I suppose you need to fill the OS-level cache: $ cat somescript.py import sys for i in range(int(sys.argv[1])): sys.stdout.write('line %d\n' % i) $ python somescript.py 20 | head -n5 line 0 line 1 line 2 line 3 line 4 $ python somescript.py 200 | head -n5 line 0 line 1 line 2 line 3 line 4 $ python somescript.py 2000 | head -n5 line 0 line 1 line 2 line 3 line 4 Traceback (most recent call last): File "somescript.py", line 4, in <module> sys.stdout.write('line %d\n' % i) IOError: [Errno 32] Broken pipe During my experiments I even got close failed in file object destructor: sys.excepthook is missing lost sys.stderr occasionally. -- https://mail.python.org/mailman/listinfo/python-list