Skip to content

cache.get returns default value when pickle reader encounters EOFError #177

Closed
ikeikeikeike wants to merge 1 commit intograntjenks:masterfrom
ikeikeikeike:pickle-read-eof
Closed

cache.get returns default value when pickle reader encounters EOFError #177
ikeikeikeike wants to merge 1 commit intograntjenks:masterfrom
ikeikeikeike:pickle-read-eof

Conversation

@ikeikeikeike
Copy link
Copy Markdown

@ikeikeikeike ikeikeikeike commented Dec 16, 2020

, which behaves in the same way as FileNotFoundError.

EOFError happened when a blank file is read by pickle reader. I don't know specifically what is going on why blank file is there, instead of large file. Although, EOFError is going to throw permanently.

FYO. The io.IOBase returns empty string instead. https://docs.python.org/3/library/exceptions.html#EOFError

(N.B.: the io.IOBase.read() and io.IOBase.readline() methods return an empty string when they hit EOF.

Addition: This PR is just to take it as a suggestion, thus it is closable.

@grantjenks
Copy link
Copy Markdown
Owner

Seems like a cache miss then? I would expect the default value, not an IOError.

@ikeikeikeike
Copy link
Copy Markdown
Author

Thanks, your response.

cache.get was working well but suddenly a file was blanked by unknown reasons.
I confirmed sqlite3's result too, which a record is still there.

@ikeikeikeike
Copy link
Copy Markdown
Author

Any idea?

The present situation, a EOFError is caught by the except-statement,
and then deal with it, which is not essential in my app code(A user cannot expect a EOFError).

Supposedly, I wonder it is broken in writing process while an unexpected occurred.
I would like you to have a deal with that an exception handling instead of strict atomically-transaction.

@grantjenks
Copy link
Copy Markdown
Owner

I don’t know how it gets into a bad state here. But I do not want to break the atomic transaction guarantee. It still looks like a cache miss to me.

For your project, the code can subclass Disk and use that for Cache initialization. Look in the docs for JSONDisk for an example.

Without understanding more about how the cache got into this state, I’m not comfortable with the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants