cgi integration question 2
Gerhard Häring
gerhard.haering at gmx.de
Sun Oct 20 10:53:18 EDT 2002
Ken wrote in comp.lang.python:
> Hello, I have this problem which I don't know what it means or how
> to fix, can someone help me?
>
> Traceback (most recent call last): File "chessboard.cgi", line 143, in ?
> outf.close() IOError: [Errno 32] Broken pipe
Dunno why, but I have a few remarks nonetheless.
> Python frontend program:
> lines = []
> outf, inf = os.popen2("knight")
> print >>outf, size #size
> print >>outf, startX #start X position
> print >>outf, startY #start Y position
> outf.close() #<<========= Refer to this line 143
> time.sleep(1)
Frankly, sleeping in the context of synchronous IO doesn't make any
sense.
> maxSize = string.atoi(size) * string.atoi(size)
> while len(lines)< maxSize:
> lines = inf.readlines() #Output produce by back end program ["34", "35",
> ...etc]
readlines() reads the *whole* output, so if after that you read again,
it will block forever. If you want to read line by line, use
readline() instead. But read the docs about read() and readline(), as
you'll find important info there, for example that if it returns an
empty string it means that you've reached EOF :-)
> if len(lines)==maxSize:
> inf.close()
> break
> time.sleep(1)
You could rewrite this as:
outf, inf = os.popen2("night")
print >>outf, ...
...
outf.close()
lines = inf.readlines()
inf.close()
-- Gerhard
More information about the Python-list
mailing list