Change in vdsm[master]: virt: ExpiringCache: implement __nonzero__

danken at redhat.com danken at redhat.com
Thu Mar 26 14:20:11 UTC 2015


Dan Kenigsberg has posted comments on this change.

Change subject: virt: ExpiringCache: implement __nonzero__
......................................................................


Patch Set 1: Code-Review-1

(2 comments)

https://gerrit.ovirt.org/#/c/39237/1/tests/vmUtilsTests.py
File tests/vmUtilsTests.py:

Line 103:         clock = FakeClock(0.0)
Line 104:         cache = utils.ExpiringCache(ttl=1.0, clock=clock)
Line 105: 
Line 106:         ITEMS = 10
Line 107:         for i in xrange(ITEMS):
where size is not the issue, and performance is not a big deal like in test, please use range() to mainatain future compat with python3
Line 108:             cache[i] = 'foobar-%d' % i
Line 109:         self.assertTrue(cache)
Line 110: 
Line 111:         clock.now = 1.1


https://gerrit.ovirt.org/#/c/39237/1/vdsm/virt/utils.py
File vdsm/virt/utils.py:

Line 90:         now = self._clock()
Line 91:         with self._lock:
Line 92:             for key in [key
Line 93:                         for key, (expiration, value)
Line 94:                         in self._items.items()
the cache can get big, can it? maybe use iteritems() and worry about python3 later?

also, despite my love to list comprehensions, I don't see the benefit of it here

for key, (expiration, value) in self._items.items():
    if expiration <= now:
        del ...

seems simpler
Line 95:                         if expiration <= now]:
Line 96:                 del self._items[key]
Line 97: 
Line 98:             return bool(self._items)


-- 
To view, visit https://gerrit.ovirt.org/39237
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I15324dc8c43fbb4ef2acb260728f09bcb9a1c975
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Martin Polednik <mpolednik at redhat.com>
Gerrit-Reviewer: Vinzenz Feenstra <vfeenstr at redhat.com>
Gerrit-Reviewer: automation at ovirt.org
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes


More information about the vdsm-patches mailing list