def acquire(self, timeout=None): """ Try to acquire a lock. Try to create the lock directory. If it fails because another lock exists, try to expire the other lock. Repeat after little sleep until timeout passed. Return True if a lock was acquired; False otherwise. """ timer = self.timerClass(timeout) timer.start() while timer.haveTime(): try: filesys.mkdir(self.lockDir) self._locked = True logging.debug('acquired exclusive lock: {0}'.format(self.lockDir, )) return True except OSError as err: if err.errno != errno.EEXIST: raise if self.expire(): continue # Try immediately to acquire timer.sleep() logging.debug('failed to acquire exclusive lock: {0}'.format(self.lockDir, )) return False
def _makeDir(self): """ Make sure directory exists """ try: filesys.mkdir(self.dir) logging.debug('created directory: %s' % self.dir) except OSError, err: if err.errno != errno.EEXIST: raise
def _store_get(self, request): path = request.cfg.session_dir try: filesys.mkdir(path) except OSError: pass return FilesystemSessionStore(path=path, filename_template='%s', session_class=MoinSession, mode=0666 & config.umask)
def acquire(self, timeout=None): """ Try to acquire a lock. Try to create the lock directory. If it fails because another lock exists, try to expire the other lock. Repeat after little sleep until timeout passed. Return True if a lock was acquired; False otherwise. """ timer = self.timerClass(timeout) timer.start() while timer.haveTime(): try: filesys.mkdir(self.lockDir) self._locked = True logging.debug('acquired exclusive lock: %s' % (self.lockDir, )) return True except OSError, err: if err.errno != errno.EEXIST: raise if self.expire(): continue # Try immediately to acquire timer.sleep()