Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

If there is no modified data, do not write.#54

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
msiemens merged 1 commit intomsiemens:masterfromrainwoodman:patch-1
May 20, 2015

Conversation

@rainwoodman
Copy link
Contributor

This avoids an exception:

Exception ValueError: 'I/O operation on closed file' in <bound method CachingMiddleware.__del__ of  <tinydb.middlewares.CachingMiddleware object at 0x7f9c96610a90>> ignored

The case happens when the objects has been closed anddel is invoked. Since the semantics guarantees
no writes after close, avoid storage.write when there are no changes in flush seems to be a reasonable fix.

This avoids an exception:    Exception ValueError: 'I/O operation on closed file' in <bound method CachingMiddleware.__del__ of  <tinydb.middlewares.CachingMiddleware object at 0x7f9c96610a90>> ignoredThe case happens when the objects has been closed and __del__ is invoked. Since the semantics guaranteesno writes after close, avoid storage.write when there are no changes in flush seems to be a reasonable fix.
@msiemens
Copy link
Owner

Thank you for the PR! Do you have an idea how this could be tested?

@rainwoodman
Copy link
ContributorAuthor

This would reproduce it. I am not sure how to integrate into the test framework; since this is an igored exception in__del__.

from tinydb import TinyDBfrom tinydb import wherefrom tinydb.storages import JSONStoragefrom tinydb.middlewares import CachingMiddlewareclass DB(TinyDB):    def __init__(self, filename):        TinyDB.__init__(self, filename, storage=CachingMiddleware(JSONStorage))        self.foo = filenamedef main():    with DB("abcd.json") as db:        for i in range(12):            db.remove(where("key") == i)            d = {'key':i,                 'value':"1231",                }            db.insert(d)main()

@msiemens
Copy link
Owner

Hmmm... The ignored exception is raised when garbage collecting the database object while the file handle has already been closed. It appears to me that on garbage collection the file handle is collected (and closed) first, followed by the storage/middleware. But this of course depends on the Python implementation and maybe even version¹, so I'll merge this PR without an accompanying test.

¹ I've tried to reliably force garbage collection of the database object, but haven't succeeded so far.

msiemens added a commit that referenced this pull requestMay 20, 2015
CachingMiddleware: Don't write if no data has been modified
@msiemensmsiemens merged commitcbcf58d intomsiemens:masterMay 20, 2015
@msiemens
Copy link
Owner

I've now released v2.3.2 which contains your changes 😃

@rainwoodmanrainwoodman deleted the patch-1 branchMay 20, 2015 17:45
@rainwoodman
Copy link
ContributorAuthor

Thanks!

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@rainwoodman@msiemens

[8]ページ先頭

©2009-2025 Movatter.jp