classification
Title: seekable() returns True on pipe objects in Windows
Type: behavior Stage:
Components: IO, Windows Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, izbyshev, nedsociety, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords:

Created on 2020-12-08 15:55 by nedsociety, last changed 2020-12-08 17:47 by izbyshev.

Messages (2)
msg382746 - (view) Author: Myungbae Son (nedsociety) Date: 2020-12-08 15:55
>>> import os
>>> r, w = os.pipe()
>>> os.lseek(w, 10, 0)
10
>>> wf = open(w, 'w')
>>> wf.seekable()
True

This happens on Windows. Consequently seek() works for these objects but they seems to be no-op. This may confuse libraries that depend on seeking.

The named pipe objects (via CreateNamedPipe -> open_osfhandle -> open()) exhibit the same behavior.
msg382753 - (view) Author: Alexey Izbyshev (izbyshev) * (Python triager) Date: 2020-12-08 17:47
Yes, despite that MSVCRT knows the type of the file descriptor because it calls GetFileType() on its creation, it doesn't check it in lseek() implementation and simply calls SetFilePointer(), which spuriously succeeds for pipes. MSDN says the following[1]:

Calling the SetFilePointer function with a handle to a non-seeking device such as a pipe or a communications device is not supported, even though the SetFilePointer function may not return an error. The behavior of the SetFilePointer function in this case is undefined.

[1] https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfilepointer
History
Date User Action Args
2021-03-12 20:40:47eryksunlinkissue40540 superseder
2020-12-08 17:47:01izbyshevsetversions: + Python 3.8, Python 3.10
nosy: + izbyshev, zach.ware, eryksun, paul.moore, tim.golden, vstinner, steve.dower

messages: + msg382753

components: + Windows
2020-12-08 15:55:37nedsocietycreate