parameters: (self)
docstring: Reopen log file if needed.
  
          Checks if the underlying file has changed, and if it
          has, close the old stream and reopen the file to get the
          current stream.
docstring_summary: Reopen log file if needed.
docstring_tokens: Reopen log file if needed .
function: def reopenIfNeeded(self):
          """
          Reopen log file if needed.
  
          Checks if the underlying file has changed, and if it
          has, close the old stream and reopen the file to get the
          current stream.
          """
          # Reduce the chance of race conditions by stat'ing by path only
          # once and then fstat'ing our new fd if we opened a new log stream.
          # See issue #14632: Thanks to John Mulligan for the problem report
          # and patch.
          try:
              # stat the file by path, checking for existence
              sres = os.stat(self.baseFilename)
          except FileNotFoundError:
              sres = None
          # compare file system stat with that of our stream file handle
          if not sres or sres[ST_DEV] != self.dev or sres[ST_INO] != self.ino:
              if self.stream is not None:
                  # we have an open file handle, clean it up
                  self.stream.flush()
                  self.stream.close()
                  self.stream = None  # See Issue #21742: _open () might fail.
                  # open a new file handle and get new stat info from that fd
                  self.stream = self._open()
                  self._statstream()
function_tokens: def reopenIfNeeded ( self ) : # Reduce the chance of race conditions by stat'ing by path only # once and then fstat'ing our new fd if we opened a new log stream. # See issue #14632: Thanks to John Mulligan for the problem report # and patch. try : # stat the file by path, checking for existence sres = os . stat ( self . baseFilename ) except FileNotFoundError : sres = None # compare file system stat with that of our stream file handle if not sres or sres [ ST_DEV ] != self . dev or sres [ ST_INO ] != self . ino : if self . stream is not None : # we have an open file handle, clean it up self . stream . flush ( ) self . stream . close ( ) self . stream = None # See Issue #21742: _open () might fail. # open a new file handle and get new stat info from that fd self . stream = self . _open ( ) self . _statstream ( )