improving initialization time and reducing async overload

This commit is contained in:
Vinícius Moreira
2019-07-08 12:15:15 -03:00
committed by GitHub
parent 735e590756
commit 74fa85a2bb
18 changed files with 577 additions and 240 deletions

25
fpakman/util/memory.py Normal file
View File

@@ -0,0 +1,25 @@
import time
from threading import Thread
from typing import List
from fpakman.util.cache import Cache
import gc
class CacheCleaner(Thread):
def __init__(self, caches: List[Cache], check_interval: int = 15):
super(CacheCleaner, self).__init__(daemon=True)
self.caches = [c for c in caches if c.is_enabled()]
self.check_interval = check_interval
def run(self):
if self.caches:
while True:
for cache in self.caches:
cache.clean_expired()
gc.collect()
time.sleep(self.check_interval)