A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2008-December/084187.html below:

[Python-Dev] Forking and pipes

[Python-Dev] Forking and pipes [Python-Dev] Forking and pipesGreg Ewing greg.ewing at canterbury.ac.nz
Wed Dec 10 01:00:40 CET 2008
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
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4