(self)
Clean up expired sessions.
Clean up expired sessions.
Clean up expired sessions .
def clean_up(self):
        """Clean up expired sessions."""

        now = self.now()
        for _id, (data, expiration_time) in list(self.cache.items()):
            if expiration_time <= now:
                try:
                    del self.cache[_id]
                except KeyError:
                    pass
                try:
                    if self.locks[_id].acquire(blocking=False):
                        lock = self.locks.pop(_id)
                        lock.release()
                except KeyError:
                    pass

        # added to remove obsolete lock objects
        for _id in list(self.locks):
            locked = (
                _id not in self.cache
                and self.locks[_id].acquire(blocking=False)
            )
            if locked:
                lock = self.locks.pop(_id)
                lock.release()
def clean_up ( self ) : now = self . now ( ) for _id , ( data , expiration_time ) in list ( self . cache . items ( ) ) : if expiration_time <= now : try : del self . cache [ _id ] except KeyError : pass try : if self . locks [ _id ] . acquire ( blocking = False ) : lock = self . locks . pop ( _id ) lock . release ( ) except KeyError : pass # added to remove obsolete lock objects for _id in list ( self . locks ) : locked = ( _id not in self . cache and self . locks [ _id ] . acquire ( blocking = False ) ) if locked : lock = self . locks . pop ( _id ) lock . release ( )