Use a monotonic time for registry cache.

So an old cache does not take precedence over a newly set value.
I noticed this bug because of the time going backward in tests
because of the time.time mock introduced in
dcf55cf6de, but this may happen
in production systems too.

Also adds another deprecation warning for python < 3.3.
This commit is contained in:
Valentin Lorentz 2019-10-05 22:29:00 +02:00
parent 702cfaaf97
commit 8b2cbbc583
3 changed files with 14 additions and 4 deletions

View File

@ -267,5 +267,10 @@ if sys.version_info < (3, 0):
'bug at <https://github.com/ProgVal/Limnoria/issues> and we\'ll '
'see together what we can do about it.',
DeprecationWarning)
if sys.version_info < (3, 3):
warnings.warn('You are installing Limnoria for Python < 3.3, which is '
'only partially support. Limnoria requires Python 3.4 or later '
'to be fully stable.',
DeprecationWarning)
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -70,6 +70,12 @@ ENCODING = 'string_escape' if minisix.PY2 else 'unicode_escape'
decoder = codecs.getdecoder(ENCODING)
encoder = codecs.getencoder(ENCODING)
if hasattr(time, 'monotonic'):
monotonic_time = time.monotonic
else:
# fallback for python < 3.3
monotonic_time = time.time
_cache = utils.InsensitivePreservingDict()
_lastModified = 0
def open_registry(filename, clear=False):
@ -105,7 +111,7 @@ def open_registry(filename, clear=False):
except ValueError:
raise InvalidRegistryFile('Error unpacking line %r' % acc)
_cache[key] = value
_lastModified = time.time()
_lastModified = monotonic_time()
_fd.close()
CONF_FILE_HEADER = """
@ -435,7 +441,7 @@ class Value(Group):
if self._name == 'unset':
self._lastModified = 0
self.__parent.setName(*args)
self._lastModified = time.time()
self._lastModified = monotonic_time()
def set(self, s):
"""Override this with a function to convert a string to whatever type
@ -456,7 +462,7 @@ class Value(Group):
inherited=True means the value is inherited from the parent, so if
the parent gets a new value, this group will get the new value as
well."""
self._lastModified = time.time()
self._lastModified = monotonic_time()
self.value = v
if self._supplyDefault:
for (name, child) in list(self._children.items()):

View File

@ -87,7 +87,6 @@ def timeFastForward(extra_offset):
mock_time_offset += extra_offset
def setupMockTime():
mock_time_offset = 0
time.time = mockTime
def teardownMockTime():