Commit 90104c33 authored by Jason Madden's avatar Jason Madden

Tweaks suggested by @tseaver

parent bfd0b7de
...@@ -74,9 +74,8 @@ class Persistent(object): ...@@ -74,9 +74,8 @@ class Persistent(object):
# The C implementation only forbids changing the jar # The C implementation only forbids changing the jar
# if we're already in a cache. Match its error message # if we're already in a cache. Match its error message
raise ValueError('can not change _p_jar of cached object') raise ValueError('can not change _p_jar of cached object')
if self.__jar == value:
return if self.__jar != value:
else:
_OSA(self, '_Persistent__jar', value) _OSA(self, '_Persistent__jar', value)
_OSA(self, '_Persistent__flags', 0) _OSA(self, '_Persistent__flags', 0)
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
from __future__ import print_function
import gc import gc
import weakref import weakref
...@@ -37,6 +36,10 @@ class RingNode(object): ...@@ -37,6 +36,10 @@ class RingNode(object):
self.prev = prev self.prev = prev
def _sweeping_ring(f): def _sweeping_ring(f):
# A decorator for functions in the PickleCache
# that are sweeping the entire ring (mutating it);
# serves as a pseudo-lock to not mutate the ring further
# in other functions
def locked(self, *args, **kwargs): def locked(self, *args, **kwargs):
self._is_sweeping_ring = True self._is_sweeping_ring = True
try: try:
...@@ -51,6 +54,8 @@ class PickleCache(object): ...@@ -51,6 +54,8 @@ class PickleCache(object):
total_estimated_size = 0 total_estimated_size = 0
cache_size_bytes = 0 cache_size_bytes = 0
# Set by functions that sweep the entire ring (via _sweeping_ring)
# Serves as a pseudo-lock
_is_sweeping_ring = False _is_sweeping_ring = False
def __init__(self, jar, target_size=0, cache_size_bytes=0): def __init__(self, jar, target_size=0, cache_size_bytes=0):
...@@ -339,6 +344,7 @@ class PickleCache(object): ...@@ -339,6 +344,7 @@ class PickleCache(object):
while (node is not self.ring while (node is not self.ring
and ( self.non_ghost_count > target and ( self.non_ghost_count > target
or (target_size_bytes and self.total_estimated_size > target_size_bytes))): or (target_size_bytes and self.total_estimated_size > target_size_bytes))):
if node.object._p_state == UPTODATE: if node.object._p_state == UPTODATE:
# The C implementation will only evict things that are specifically # The C implementation will only evict things that are specifically
# in the up-to-date state # in the up-to-date state
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment