def _cleanupNodeRequestLocks(self): ''' Remove request locks where the request no longer exists. Because the node request locks are not direct children of the request znode, we need to remove the locks separately after the request has been processed. Only remove them after LOCK_CLEANUP seconds have passed. This helps reduce chances of the scenario where a request could go away _while_ a lock is currently held for processing and the cleanup thread attempts to delete it. The delay should reduce the chance that we delete a currently held lock. ''' zk = self._nodepool.getZK() requests = zk.getNodeRequests() now = time.time() for lock_stat in zk.nodeRequestLockStatsIterator(): if lock_stat.lock_id in requests: continue if (now - lock_stat.stat.mtime / 1000) > LOCK_CLEANUP: zk.deleteNodeRequestLock(lock_stat.lock_id)