def acquire(self): """ Acquire thread and file locks. Re-opening log for 'degraded' mode. """ # handle thread lock Handler.acquire(self) # Issue a file lock. (This is inefficient for multiple active threads # within a single process. But if you're worried about high-performance, # you probably aren't using this log handler.) if self.stream_lock: # If stream_lock=None, then assume close() was called or something # else weird and ignore all file-level locks. if self.stream_lock.closed: # Daemonization can close all open file descriptors, see # https://bugzilla.redhat.com/show_bug.cgi?id=952929 # Try opening the lock file again. Should we warn() here?!? try: self._open_lockfile() except Exception: self.handleError(NullLogRecord()) # Don't try to open the stream lock again self.stream_lock = None return lock(self.stream_lock, LOCK_EX) # 0.9.1a: Here we got file lock if not os.path.isfile(self.baseFilename): # file not exists: self._close() self.stream = self._open()
def acquire(self): """ Acquire thread and file locks. Re-opening log for 'degraded' mode. """ # handle thread lock if Handler: # under some tests Handler ends up being null due to instantiation # order Handler.acquire(self) # Issue a file lock. (This is inefficient for multiple active threads # within a single process. But if you're worried about high-performance, # you probably aren't using this log handler.) if self.stream_lock: # If stream_lock=None, then assume close() was called or something # else weird and ignore all file-level locks. if self.stream_lock.closed: # Daemonization can close all open file descriptors, see # https://bugzilla.redhat.com/show_bug.cgi?id=952929 # Try opening the lock file again. Should we warn() here?!? try: self._open_lockfile() except Exception: self.handleError(NullLogRecord()) # Don't try to open the stream lock again self.stream_lock = None return lock(self.stream_lock, LOCK_EX)
def acquire(self): """ Acquire thread and file locks. Also re-opening log file when running in 'degraded' mode. """ # handle thread lock Handler.acquire(self) lock(self.stream_lock, LOCK_EX) if self.stream.closed: self._openFile(self.mode)
def acquire(self): """ Acquire thread and file locks. Also re-opening log file when running in 'degraded' mode. """ # handle thread lock Handler.acquire(self) lock(self.stream_lock, LOCK_EX) if self.stream.closed: try: self._openFile(self.mode) except IOError: #fail - abort logging self._disable()
def acquire(self): Handler.acquire(self) if self.stream_lock: if self.stream_lock.closed(): try: self._open_lockfile() except Exception: self.handleError(NullLogRecord()) self.stream_lock = None return self.stream_lock.acquire()
def acquire(self): """ Acquire thread and file locks. Re-opening log for 'degraded' mode. """ Handler.acquire(self) if self.stream_lock: if self.stream_lock.closed: try: self._open_lockfile() except Exception: self.handleError(NullLogRecord()) self.stream_lock = None return lock(self.stream_lock, LOCK_EX)
def acquire(self): """ 获取文件锁和线程锁,如果滚动失败则关闭文件 :return: None :raises: NullLogRecord 日志输出异常 """ # 获得线程锁 Handler.acquire(self) # 处理文件锁,如果stream锁已经close则什么也不做 if self.stream_lock: if self.stream_lock.closed: try: self._open_lockfile() except Exception: self.handleError(NullLogRecord()) self.stream_lock = None return self._lock(self.stream_lock, fcntl.LOCK_EX)
def acquire(self): """ Acquire thread and file locks. Also re-opening log file when running in 'degraded' mode. """ # handle thread lock Handler.acquire(self) try: lock(self.stream_lock, LOCK_EX) except IOError: # lock failed - abort logging self._disable() return try: #self.stream_lock.write(str(os.getpid()) + ' aq\n') if self.stream and self.stream.closed: try: self._openFile(self.mode) except IOError: #fail - abort logging self._disable() except: #unknown error unlock(self.stream_lock) raise
def acquire(self): """ Acquire thread and file locks. Re-opening log for 'degraded' mode. """ self._console_log("In acquire", stack=True) # Handle thread lock Handler.acquire(self) # Noinspection PyBroadException try: self._open_lockfile() except Exception: self.handleError(NullLogRecord()) self._stream_lock_count += 1 self._console_log(">> stream_lock_count = %s" % (self._stream_lock_count, )) if self._stream_lock_count == 1: self._console_log(">Getting lock for %s" % (self.stream_lock, ), stack=True) lock(self.stream_lock, LOCK_EX) self.stream = self._open()
def acquire(self): Handler.acquire(self) fcntl.flock(self.stream_lock, fcntl.LOCK_EX) if self.stream.closed: self._openFile(self.mode)