1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Made psutil optional

This commit is contained in:
Krateng 2020-05-29 17:39:19 +02:00
parent 98c1527f77
commit b21b27bb6e
2 changed files with 17 additions and 12 deletions

View File

@ -5,7 +5,7 @@ author = {
"email":"maloja@krateng.dev",
"github": "krateng"
}
version = 2,4,8
version = 2,4,9
versionstr = ".".join(str(n) for n in version)
links = {
"pypi":"malojaserver",
@ -21,8 +21,7 @@ requires = [
"wand>=0.5.4",
"lesscpy>=0.13",
"jinja2>2.11",
"lru-dict>=1.1.6",
"psutil>0.5.0"
"lru-dict>=1.1.6"
]
resources = [
"web/*/*/*",

View File

@ -34,7 +34,6 @@ from collections import namedtuple
from threading import Lock
import yaml
import lru
import psutil
# url handling
from importlib.machinery import SourceFileLoader
@ -1057,6 +1056,11 @@ else:
csz = settings.get_settings("DB_CACHE_ENTRIES")
cmp = settings.get_settings("DB_MAX_MEMORY")
try:
import psutil
use_psutil = True
except:
use_psutil = False
cache_query = lru.LRU(csz)
cache_query_perm = lru.LRU(csz)
@ -1121,10 +1125,11 @@ def db_query_cached(**kwargs):
if eligible_permanent_caching: cache_query_perm[key] = result
elif eligible_temporary_caching: cache_query[key] = result
ramprct = psutil.virtual_memory().percent
if ramprct > cmp:
log("{prct} RAM usage, dumping temporary caches!".format(prct=ramprct),module="debug")
invalidate_caches()
if use_psutil:
ramprct = psutil.virtual_memory().percent
if ramprct > cmp:
log("{prct} RAM usage, dumping temporary caches!".format(prct=ramprct),module="debug")
invalidate_caches()
return result
@ -1159,10 +1164,11 @@ def db_aggregate_cached(**kwargs):
if eligible_permanent_caching: cache_aggregate_perm[key] = result
elif eligible_temporary_caching: cache_aggregate[key] = result
ramprct = psutil.virtual_memory().percent
if ramprct > cmp:
log("{prct} RAM usage, dumping temporary caches!".format(prct=ramprct),module="debug")
invalidate_caches()
if use_psutil:
ramprct = psutil.virtual_memory().percent
if ramprct > cmp:
log("{prct} RAM usage, dumping temporary caches!".format(prct=ramprct),module="debug")
invalidate_caches()
return result