Please help with feeding a popen2 pipe with a large input

Alain TESIO alain at onesite.org
Wed Jan 10 11:16:37 EST 2001


Hi,
Hi, I'm trying to use popen2 (on a linux machine), I can't write more than 16K in the
input stream and I can't figure out how to use the bufsize parameter.
I've tried to open the pipe with bufsize=1000 and write 1000 bytes at a time.

Here is the test program I'm using with a pipe to cat and the output, it hangs when trying
to write the 16th block.

Any hint is welcome !

Alain


total length is 249866, bufsize is 1000
writing from 0 to 999 ...ok
writing from 1000 to 1999 ...ok
writing from 2000 to 2999 ...ok
writing from 3000 to 3999 ...ok
writing from 4000 to 4999 ...ok
writing from 5000 to 5999 ...ok
writing from 6000 to 6999 ...ok
writing from 7000 to 7999 ...ok
writing from 8000 to 8999 ...ok
writing from 9000 to 9999 ...ok
writing from 10000 to 10999 ...ok
writing from 11000 to 11999 ...ok
writing from 12000 to 12999 ...ok
writing from 13000 to 13999 ...ok
writing from 14000 to 14999 ...ok
writing from 15000 to 15999 ...ok
writing from 16000 to 16999 ...


def MyPipe(command,string_in):
	bufsize=1000
	import popen2
	(pipe_out,pipe_in,pipe_err)=popen2.popen3(command,bufsize)
	l=len(string_in)
	sys.stdout.write("total length is %i, bufsize is %i\n" % (l,bufsize))
	start=0
	end=0
	while end<l:
		end=min(l,start+bufsize)
		sys.stdout.write("writing from %i to %i ..." % (start,end-1))
		pipe_in.write(string_in[start:end])
		sys.stdout.write("ok\n")
		start=start+bufsize
	sys.stdout.write("closing pipe stdin")
	pipe_in.close()
	string_err=pipe_err.read()
	pipe_err.close()
	string_out=pipe_out.read()
	pipe_out.close()
	return (string_out,string_err)

f=open("tmp")
h=f.read()
f.close()

(out,err)=MyPipe("cat",h)




More information about the Python-list mailing list