MCPcopy Index your code
hub / github.com/python/cpython / reopenIfNeeded

Method reopenIfNeeded

Lib/logging/handlers.py:500–534  ·  view source on GitHub ↗

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.

(self)

Source from the content-addressed store, hash-verified

498 self.ino = sres.st_ino
499
500 def reopenIfNeeded(self):
501 """
502 Reopen log file if needed.
503
504 Checks if the underlying file has changed, and if it
505 has, close the old stream and reopen the file to get the
506 current stream.
507 """
508 if self.stream is None:
509 return
510
511 # Reduce the chance of race conditions by stat'ing by path only
512 # once and then fstat'ing our new fd if we opened a new log stream.
513 # See issue #14632: Thanks to John Mulligan for the problem report
514 # and patch.
515 try:
516 # stat the file by path, checking for existence
517 sres = os.stat(self.baseFilename)
518
519 # compare file system stat with that of our stream file handle
520 reopen = (sres.st_dev != self.dev or sres.st_ino != self.ino)
521 except FileNotFoundError:
522 reopen = True
523
524 if not reopen:
525 return
526
527 # we have an open file handle, clean it up
528 self.stream.flush()
529 self.stream.close()
530 self.stream = None # See Issue #21742: _open () might fail.
531
532 # open a new file handle and get new stat info from that fd
533 self.stream = self._open()
534 self._statstream()
535
536 def emit(self, record):
537 """

Callers 1

emitMethod · 0.95

Calls 5

_statstreamMethod · 0.95
statMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45
_openMethod · 0.45

Tested by

no test coverage detected