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

Method _refresh

Lib/mailbox.py:571–607  ·  view source on GitHub ↗

Update table of contents mapping.

(self)

Source from the content-addressed store, hash-verified

569 path)
570
571 def _refresh(self):
572 """Update table of contents mapping."""
573 # If it has been less than two seconds since the last _refresh() call,
574 # we have to unconditionally re-read the mailbox just in case it has
575 # been modified, because os.path.mtime() has a 2 sec resolution in the
576 # most common worst case (FAT) and a 1 sec resolution typically. This
577 # results in a few unnecessary re-reads when _refresh() is called
578 # multiple times in that interval, but once the clock ticks over, we
579 # will only re-read as needed. Because the filesystem might be being
580 # served by an independent system with its own clock, we record and
581 # compare with the mtimes from the filesystem. Because the other
582 # system's clock might be skewing relative to our clock, we add an
583 # extra delta to our wait. The default is one tenth second, but is an
584 # instance variable and so can be adjusted if dealing with a
585 # particularly skewed or irregular system.
586 if time.time() - self._last_read > 2 + self._skewfactor:
587 refresh = False
588 for subdir in self._toc_mtimes:
589 mtime = os.path.getmtime(self._paths[subdir])
590 if mtime > self._toc_mtimes[subdir]:
591 refresh = True
592 self._toc_mtimes[subdir] = mtime
593 if not refresh:
594 return
595 # Refresh toc
596 self._toc = {}
597 for subdir in self._toc_mtimes:
598 path = self._paths[subdir]
599 for entry in os.listdir(path):
600 if entry.startswith('.'):
601 continue
602 p = os.path.join(path, entry)
603 if os.path.isdir(p):
604 continue
605 uniq = entry.split(self.colon)[0]
606 self._toc[uniq] = os.path.join(subdir, entry)
607 self._last_read = time.time()
608
609 def _lookup(self, key):
610 """Use TOC to return subpath for given key, or raise a KeyError."""

Callers 7

iterkeysMethod · 0.95
__contains__Method · 0.95
__len__Method · 0.95
_lookupMethod · 0.95
test_refreshMethod · 0.80
test_rereadMethod · 0.80

Calls 6

listdirMethod · 0.80
timeMethod · 0.45
startswithMethod · 0.45
joinMethod · 0.45
isdirMethod · 0.45
splitMethod · 0.45

Tested by 3

test_refreshMethod · 0.64
test_rereadMethod · 0.64