[Python-3000] iostack, continued

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Jun 13 02:45:51 CEST 2006


Michael Chermside wrote:
> Greg Ewing writes:
> 
>> Be careful -- in Unix it's possible for different file
>> descriptors to share the same position pointer.
> 
> Really? I had no idea.
> 
> How does one invoke this behavior?

It happens every time you fork, and the child process
inherits copies of the stdin/out/err descriptors. If
e.g. stdin is coming from a disk file, and the child
reads part of the file, and then the parent reads
some more, it will start reading where the child
left off.

Another way is to use dup() or dup2() to make a
copy of a file descriptor.

> How does current python (2.4)
> behave when subjected to this?

Calls in the os module behave the same as their
underlying system calls. File objects behave
however the platform's C stdio library behaves.

Buffering makes things a bit messy. Usually it's
not a problem, because normally parent and child
processes don't both read or write the same
disk file. If they do, some flushing calls might
be necessary.

--
Greg




More information about the Python-3000 mailing list