[Python-checkins] commit of r41662 - in python/trunk: Misc/NEWS Objects/fileobject.c configure configure.in pyconfig.h.in
Guido van Rossum
guido at python.org
Wed Dec 14 04:34:30 CET 2005
On 12/13/05, Hye-Shik Chang <hyeshik at gmail.com> wrote:
> On 12/14/05, Guido van Rossum <guido at python.org> wrote:
> > Isn't it expensive to call isatty() on every tell() call? Is it worth
> > it just to make a unit test pass?
> >
>> Indeed. isatty() requires a system call. I think it's somewhat expensive
> in case of using tell() for file monitoring or progress bars. But,
> it's just for platforms that doesn't return error for ttys. And it's
> not clearly defined for ftell(3) in POSIX:
>> [ESPIPE]
> The file descriptor underlying stream is associated with a pipe or FIFO.
> [ESPIPE]
> The file descriptor underlying stream is associated with a socket.
>> But, our library reference says that tty.seek() will raise IOError.
> So, I thought it should make some consistency.
That's a somewhat dangerous practice. The library manual is most
likely documenting observed behavior, not intended behavior -- the
intention was to match the semantics of the underlying OS. (I know
about the intentions because it's mainly all my code. :-)
But see below.
> > Or is there a real bug caused by tell() lying?
>> I don't think it's harm to keep the original behavior as before this fix.
> But file.tell() is quite cheap operation among routines likely enclose
> the operation. Hmm. If isatty() for every call still looks too expensive,
> we can just fix documentation and unittest. I'm quite neutral for the
> problem because tty.tell() is quite non-sense. :)
Unfortunately there is now code that depends on the documented
behavior. In httplib (and perhaps other mail-header-parsing code)
there's a flag 'seekable' that's set to True iff tell() succeeds.
While it's unlikely that anyone would attempt to read mail from a tty
device, I now believe that forcing the failure if isatty() is the
right thing to do.
Sorry for the waffling...
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-checkins
mailing list