10000 fstat mmap file only once · benxiaolang-hacker/client_python@b325a5e · GitHub
[go: up one dir, main page]

Skip to content

Commit b325a5e

Browse files
committed
fstat mmap file only once
Signed-off-by: Aarni Koskela <akx@iki.fi>
1 parent b91aff3 commit b325a5e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

prometheus_client/mmap_dict.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ class MmapedDict(object):
3737
def __init__(self, filename, read_mode=False):
3838
self._f = open(filename, 'rb' if read_mode else 'a+b')
3939
self._fname = filename
40-
if os.fstat(self._f.fileno()).st_size == 0:
40+
capacity = os.fstat(self._f.fileno()).st_size
41+
if capacity == 0:
4142
self._f.truncate(_INITIAL_MMAP_SIZE)
42-
self._capacity = os.fstat(self._f.fileno()).st_size
43+
capacity = _INITIAL_MMAP_SIZE
44+
self._capacity = capacity
4345
self._m = mmap.mmap(self._f.fileno(), self._capacity,
4446
access=mmap.ACCESS_READ if read_mode else mmap.ACCESS_WRITE)
4547

0 commit comments

Comments
 (0)
0