-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Cannot seek on write only tf.gfile.GFile #32122
Comments
Related to #32090, right? |
It is at least related in the sense that GFile does not behave as normal Python file like objects. This specific bug seems to be caused by an assumption that only readable files can be seeked. |
Well, yes, the API is incomplete. My work on modular filesystems will first separate all filesystems into DSOs and then write a test for functionality requirements and then we can start completing the API and checking in every system to make sure it works. Maybe even fuzz the entire thing |
def test_seek_v1():
with open('file.txt', 'w+') as f: # create a new file or truncates it
f.write("test 1\n")
f.write("test 2\n")
f.write("test 3\n") # now the file pointer is at the end
f.seek(0) # move the file pointer to the beginning
lines = f.read() # read it, now we can read!
print(lines) # print it
def test_seek_v2():
with tf.io.gfile.GFile('file.txt', 'w+') as f: # create a new file or truncates it
f.write("test 1\n")
f.write("test 2\n")
f.write("test 3\n") # now the file pointer is at the end
f.seek(0) # move the file pointer to the beginning
lines = f.read() # read it, now we can read!
print(lines) # print it |
I think |
The This issue is about calling |
|
My bad, I misread the |
@eirism The provided code will trigger an error because you're attempting to call f.seek(0) on a file opened in write-only mode ('w'). Seeking is only supported for files opened in read or read/write modes.
Thank you! |
@sushreebarsa I had the same comment a while ago and got #32122 (comment) as reply (which makes sense) |
@sushreebarsa Normal Python file IO supports .seek() on files opened in write-only mode ('w'), so I expect GFile to also support it. In normal Python file IO .seek() moves the file object position and allows you to overwrite already written data. The following code using normal Python file IO will write "Hello" to the text file "test.txt" by using .seek() to overwrite the first character written to file:
|
System information
Describe the current behavior
Calling
seek()
on atf.gfile.GFile
opened in write only mode raisestensorflow.python.framework.errors_impl.PermissionDeniedError
.Describe the expected behavior
GFile should support the Python IO semantics that supports seeking on a write only file.
More generally it would be preferable if GFile followed the API of Python's
io.IOBase
.Code to reproduce the issue
Other info / logs
The text was updated successfully, but these errors were encountered: