'Clean up expired sessions.'

def clean_up(self):

    now = self.now()
    for (_id, (data, expiration_time)) in copyitems(self.cache):
        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
    for _id in list(self.locks):
        if ((_id not in self.cache) and self.locks[_id].acquire(blocking=False)):
            lock = self.locks.pop(_id)
            lock.release()
