[MRG] fix race condition in utils.lock