mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 08:14:16 +02:00
[view] fix: random segmentation fault errors caused by the cache cleaner thread
This commit is contained in:
@@ -37,6 +37,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
### Fixes
|
### Fixes
|
||||||
- AppImage
|
- AppImage
|
||||||
- upgrade fails when the package was initially imported, but later added to bauh's database [#321](https://github.com/vinifmor/bauh/issues/321)
|
- upgrade fails when the package was initially imported, but later added to bauh's database [#321](https://github.com/vinifmor/bauh/issues/321)
|
||||||
|
- General
|
||||||
|
- random segmentation fault errors associated with threads and caching
|
||||||
- Web
|
- Web
|
||||||
- search not working for some typed addresses (e.g: those returning 403)
|
- search not working for some typed addresses (e.g: those returning 403)
|
||||||
|
|
||||||
|
|||||||
@@ -18,16 +18,14 @@ from bauh.view.qt.prepare import PreparePanel
|
|||||||
from bauh.view.qt.settings import SettingsWindow
|
from bauh.view.qt.settings import SettingsWindow
|
||||||
from bauh.view.qt.window import ManageWindow
|
from bauh.view.qt.window import ManageWindow
|
||||||
from bauh.view.util import resource, util
|
from bauh.view.util import resource, util
|
||||||
from bauh.view.util.cache import CacheCleaner, DefaultMemoryCacheFactory
|
from bauh.view.util.cache import DefaultMemoryCacheFactory
|
||||||
from bauh.view.util.disk import DefaultDiskCacheLoaderFactory
|
from bauh.view.util.disk import DefaultDiskCacheLoaderFactory
|
||||||
|
|
||||||
|
|
||||||
def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logger) -> Tuple[QApplication, QWidget]:
|
def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logger) -> Tuple[QApplication, QWidget]:
|
||||||
i18n = generate_i18n(app_config, resource.get_path('locale'))
|
i18n = generate_i18n(app_config, resource.get_path('locale'))
|
||||||
|
|
||||||
cache_cleaner = CacheCleaner()
|
cache_factory = DefaultMemoryCacheFactory(expiration_time=int(app_config['memory_cache']['data_expiration']))
|
||||||
|
|
||||||
cache_factory = DefaultMemoryCacheFactory(expiration_time=int(app_config['memory_cache']['data_expiration']), cleaner=cache_cleaner)
|
|
||||||
icon_cache = cache_factory.new(int(app_config['memory_cache']['icon_expiration']))
|
icon_cache = cache_factory.new(int(app_config['memory_cache']['icon_expiration']))
|
||||||
|
|
||||||
http_client = HttpClient(logger)
|
http_client = HttpClient(logger)
|
||||||
@@ -83,12 +81,9 @@ def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logg
|
|||||||
force_suggestions=force_suggestions,
|
force_suggestions=force_suggestions,
|
||||||
logger=logger)
|
logger=logger)
|
||||||
|
|
||||||
prepare = PreparePanel(context=context,
|
return app, PreparePanel(context=context,
|
||||||
manager=manager,
|
manager=manager,
|
||||||
i18n=i18n,
|
i18n=i18n,
|
||||||
manage_window=manage_window,
|
manage_window=manage_window,
|
||||||
app_config=app_config,
|
app_config=app_config,
|
||||||
force_suggestions=force_suggestions)
|
force_suggestions=force_suggestions)
|
||||||
cache_cleaner.start()
|
|
||||||
|
|
||||||
return app, prepare
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import time
|
from threading import Lock
|
||||||
from threading import Lock, Thread
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from bauh.api.abstract.cache import MemoryCache, MemoryCacheFactory
|
from bauh.api.abstract.cache import MemoryCache, MemoryCacheFactory
|
||||||
@@ -76,41 +75,14 @@ class DefaultMemoryCache(MemoryCache):
|
|||||||
self.get(key)
|
self.get(key)
|
||||||
|
|
||||||
|
|
||||||
class CacheCleaner(Thread):
|
|
||||||
|
|
||||||
def __init__(self, check_interval: int = 15):
|
|
||||||
super(CacheCleaner, self).__init__(daemon=True)
|
|
||||||
self.caches = []
|
|
||||||
self.check_interval = check_interval
|
|
||||||
|
|
||||||
def register(self, cache: MemoryCache):
|
|
||||||
if cache.is_enabled():
|
|
||||||
self.caches.append(cache)
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
if self.caches:
|
|
||||||
while True:
|
|
||||||
for cache in self.caches:
|
|
||||||
cache.clean_expired()
|
|
||||||
|
|
||||||
time.sleep(self.check_interval)
|
|
||||||
|
|
||||||
|
|
||||||
class DefaultMemoryCacheFactory(MemoryCacheFactory):
|
class DefaultMemoryCacheFactory(MemoryCacheFactory):
|
||||||
|
|
||||||
def __init__(self, expiration_time: int, cleaner: CacheCleaner = None):
|
def __init__(self, expiration_time: int):
|
||||||
"""
|
"""
|
||||||
:param expiration_time: default expiration time for all instantiated caches
|
:param expiration_time: default expiration time for all instantiated caches
|
||||||
:param cleaner
|
|
||||||
"""
|
"""
|
||||||
super(DefaultMemoryCacheFactory, self).__init__()
|
super(DefaultMemoryCacheFactory, self).__init__()
|
||||||
self.expiration_time = expiration_time
|
self.expiration_time = expiration_time
|
||||||
self.cleaner = cleaner
|
|
||||||
|
|
||||||
def new(self, expiration: Optional[int] = None) -> MemoryCache:
|
def new(self, expiration: Optional[int] = None) -> MemoryCache:
|
||||||
instance = DefaultMemoryCache(expiration if expiration is not None else self.expiration_time)
|
return DefaultMemoryCache(expiration if expiration is not None else self.expiration_time)
|
||||||
|
|
||||||
if self.cleaner:
|
|
||||||
self.cleaner.register(instance)
|
|
||||||
|
|
||||||
return instance
|
|
||||||
|
|||||||
Reference in New Issue
Block a user