popen2: Broken pipe for large files

Donn Cave donn at u.washington.edu
Mon Jun 10 18:48:06 EDT 2002

Quoth Milos Prudek <milos.prudek at tiscali.cz>:
| In Python 2.1, is there a size limit when creating pipes with popen2() ?
| The following function fails because of a broken pipe if the size of T 
| is larger than 21000:
| T=File.read()
| cmd='file -b -'
| w,r=os.popen2(cmd,'b',1000000)
| w.write(T)
| w.close()
| X = r.read().split()
| print X

I suppose the "file" command only reads so much data (and probably
doesn't use all of that, as it is only interested in the top of the
file.)  When python tries to write more data, the pipe is already
closed and that's an error.

| The only possible solution so far is to change the first line:
| T=File.read()[:20000]

Sure, that will work, though it might be more economical to write

  T = File.read(20000)

	Donn Cave, donn at u.washington.edu

More information about the Python-list mailing list