예제 #1
0
 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()
예제 #2
0
    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)
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
 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()
예제 #6
0
 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()
예제 #7
0
파일: logmgr.py 프로젝트: JarodLi/obssftp
 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()
예제 #8
0
 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)
예제 #9
0
파일: log.py 프로젝트: wayhk/ARK
    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)
예제 #10
0
 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
예제 #11
0
    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()
예제 #12
0
 def acquire(self):
     Handler.acquire(self)
     fcntl.flock(self.stream_lock, fcntl.LOCK_EX)
     if self.stream.closed:
         self._openFile(self.mode)