#5843: race condition in cached_method (should not be shared between instances)
----------------------+-----------------------------------------------------
Reporter: nthiery | Owner: mhansen
Type: defect | Status: new
Priority: critical | Milestone: sage-3.4.2
Component: misc | Keywords: race condition, cached_method, cache
----------------------+-----------------------------------------------------
Consider the following class (simplified from a real life example, after 3
hours of heisenbug debugging):
{{{
class bla:
def __init__(self, value):
self.value = value
#
@cached_method
def f(self, x):
return self.value
}}}
The method f ignores its input, and should return self.value:
{{{
sage: x = bla(1)
sage: y = bla(2)
sage: x.f(None)
1
sage: y.f(None)
2
}}}
Then, y.f(x.f) should ignore the inner x.f and return 2. It does not:
{{{
sage: sage: y.f(x.f)
1
}}}
The reason is that x.f and y.f, and all other instances of bla share the
same cached_method object.
{{{
sage: x.f is y.f
True
sage: x.f is x.__class__.f
True
}}}
and the _instance field is set to the latest instance for which this
method has been queried:
{{{
sage: yf = y.f
sage: yf._instance is y
True
sage: x.f
Cached version of <function f at 0xb532d84>
sage: yf._instance is y
False
sage: yf._instance is x
True
}}}
Most of the time things work well, but there can be race conditions, as in
the example above.
Nicolas and Florent
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5843>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---