Lars Kotthoff wrote:

This prints out "foo" twice although it's only written once to the pipe. It
seems that python doesn't flush file descriptors before copying them to the
child process, thus resulting in the duplicate message. The equivalent C
program behaves as expected,

Your Python and C programs are not equivalent -- the C one is
writing directly to the file descriptor, whereas the Python one
is effectively using a buffered stdio stream. The unflushed stdio
buffer is getting copied by the fork, hence the duplicate output.

Solution: either (a) flush the Python file object before forking
or (b) use os.write() directly on the fd to avoid the buffering.

--
Greg
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to