MCPcopy Index your code
hub / github.com/RustPython/RustPython / reopenIfNeeded

Method reopenIfNeeded

Lib/logging/handlers.py:496–530  ·  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

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

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