-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
race condition in cached_method (should not be shared between instances) #5843
Comments
comment:1
Possible correct implementation: |
Attachment: 5843_CachedMethodCaller.patch.gz |
comment:2
I added a patch that returns a (newly created) Additionally this object has a Using a function/closure would also handle the caching (and I added a comment in the patch on how to do it exactly), but you would lose the ability to call methods like |
Author: Willem Palenstijn |
comment:3
Excellent patch (I couldn't figure out how to fix this, glad you did), but there doesn't seem to be a test for the main problem:
The method f ignores its input, and should return self.value:
Then, y.f(x.f) should ignore the inner x.f and return 2. It does not:
|
Reviewer: Tim Dumol |
comment:4
Attachment: 5843_doctests.patch.gz Good point. I replaced the doctest patch with one that adds a more direct test for this ticket. |
comment:5
Nice. I'm giving this a positive review, but I've attached a little patch that transfers some of the documentation from the |
Attachment: trac_5843-doctests-ref.patch.gz Adds a little bit more documentation to CachedMethod. |
Attachment: trac_5843-doctests-ref.2.patch.gz Changes the doctest to use |
comment:6
Looks good. Thanks! Patches to apply, in order: |
Changed author from Willem Palenstijn to Willem Jan Palenstijn |
Merged: sage-4.3.2.alpha0 |
comment:7
Merged patches in this order:
|
comment:8
Willem, Tim: thanks so much for fixing this! |
comment:9
Btw: #383 plays similar trick. Maybe Sage (actually Python) should have a standard tool for method wrappers as there already is for functions (see functools.wrapper). |
Consider the following class (simplified from a real life example, after 3 hours of heisenbug debugging):
The method f ignores its input, and should return self.value:
Then, y.f(x.f) should ignore the inner x.f and return 2. It does not:
The reason is that x.f and y.f, and all other instances of bla share the same cached_method object.
and the _instance field is set to the latest instance for which this method has been queried:
Most of the time things work well, but there can be race conditions, as in the example above.
Nicolas and Florent
CC: @sagetrac-sage-combinat @mwhansen
Component: misc
Keywords: race condition, cached_method, cache
Author: Willem Jan Palenstijn
Reviewer: Tim Dumol
Merged: sage-4.3.2.alpha0
Issue created by migration from https://trac.sagemath.org/ticket/5843
The text was updated successfully, but these errors were encountered: