-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-86768: check if fd is seekable in os.lseek on Windows #133137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be slightly simpler if set result to -1 initially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
|
hello, is it the function that is called when doing if yes, I am somewhat concerned about the performance impact of adding a syscall on every call. is it really needed? seek is very heavily used by applications and it is performance sensitive. |
|
For example, you can write a ZIP file to not seekable file. If the output file is seekable, It is unfortunate that this change will add 0.3 microseconds for each |
|
@zooba, could you please take a look? I believe this change should be merged, despite its performance impact. |
|
Why not change My general rule is that I don't like predicting what errors the OS should return. It's weird that it doesn't produce an error here, but I guess it breaks a lot of apps to introduce it (which should also warn us against introducing an error...). But if we have to do extra work for a bool result like |
The Line 655 in cfcfbdd
Changing the seekable method for FileIO to check if it's a pipe on Windows is also a solution, but I think the |
Fair, but in that case, I'd prefer we check specifically for a pipe and raise, rather than "anything that isn't disk". It's less disruptive to add new exceptions for specific cases than for negative cases. |
These are the LBYL and EAFP sides of the same problem. Some code uses
Does this work for "CON", "NUL" and " |
Maybe? I think My point is that we should make a list of things that are definitely not seekable and handle those, rather than making a list of things that definitely are seekable and assume that all others should be an error. |
|
According to the On Linux, And what is the correct behavior for FILE_TYPE_UNKNOWN? |
Seems reasonable.
I think allow it to work, so that cases where seeking work aren't blocked. Cases where seeking is an error can return an error if they want, but if they want it to be a no-op like pipes, then they can do that too. |
This change will introduce a performance regression:
Before the change:
After the change:
However I think it's acceptable because we added a check in the implementation and
os.lseekusually won't been called too many times in the real world.