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:
parent
98c1527f77
commit
b21b27bb6e
@ -5,7 +5,7 @@ author = {
|
|||||||
"email":"maloja@krateng.dev",
|
"email":"maloja@krateng.dev",
|
||||||
"github": "krateng"
|
"github": "krateng"
|
||||||
}
|
}
|
||||||
version = 2,4,8
|
version = 2,4,9
|
||||||
versionstr = ".".join(str(n) for n in version)
|
versionstr = ".".join(str(n) for n in version)
|
||||||
links = {
|
links = {
|
||||||
"pypi":"malojaserver",
|
"pypi":"malojaserver",
|
||||||
@ -21,8 +21,7 @@ requires = [
|
|||||||
"wand>=0.5.4",
|
"wand>=0.5.4",
|
||||||
"lesscpy>=0.13",
|
"lesscpy>=0.13",
|
||||||
"jinja2>2.11",
|
"jinja2>2.11",
|
||||||
"lru-dict>=1.1.6",
|
"lru-dict>=1.1.6"
|
||||||
"psutil>0.5.0"
|
|
||||||
]
|
]
|
||||||
resources = [
|
resources = [
|
||||||
"web/*/*/*",
|
"web/*/*/*",
|
||||||
|
@ -34,7 +34,6 @@ from collections import namedtuple
|
|||||||
from threading import Lock
|
from threading import Lock
|
||||||
import yaml
|
import yaml
|
||||||
import lru
|
import lru
|
||||||
import psutil
|
|
||||||
|
|
||||||
# url handling
|
# url handling
|
||||||
from importlib.machinery import SourceFileLoader
|
from importlib.machinery import SourceFileLoader
|
||||||
@ -1057,6 +1056,11 @@ else:
|
|||||||
|
|
||||||
csz = settings.get_settings("DB_CACHE_ENTRIES")
|
csz = settings.get_settings("DB_CACHE_ENTRIES")
|
||||||
cmp = settings.get_settings("DB_MAX_MEMORY")
|
cmp = settings.get_settings("DB_MAX_MEMORY")
|
||||||
|
try:
|
||||||
|
import psutil
|
||||||
|
use_psutil = True
|
||||||
|
except:
|
||||||
|
use_psutil = False
|
||||||
|
|
||||||
cache_query = lru.LRU(csz)
|
cache_query = lru.LRU(csz)
|
||||||
cache_query_perm = 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
|
if eligible_permanent_caching: cache_query_perm[key] = result
|
||||||
elif eligible_temporary_caching: cache_query[key] = result
|
elif eligible_temporary_caching: cache_query[key] = result
|
||||||
|
|
||||||
ramprct = psutil.virtual_memory().percent
|
if use_psutil:
|
||||||
if ramprct > cmp:
|
ramprct = psutil.virtual_memory().percent
|
||||||
log("{prct} RAM usage, dumping temporary caches!".format(prct=ramprct),module="debug")
|
if ramprct > cmp:
|
||||||
invalidate_caches()
|
log("{prct} RAM usage, dumping temporary caches!".format(prct=ramprct),module="debug")
|
||||||
|
invalidate_caches()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -1159,10 +1164,11 @@ def db_aggregate_cached(**kwargs):
|
|||||||
if eligible_permanent_caching: cache_aggregate_perm[key] = result
|
if eligible_permanent_caching: cache_aggregate_perm[key] = result
|
||||||
elif eligible_temporary_caching: cache_aggregate[key] = result
|
elif eligible_temporary_caching: cache_aggregate[key] = result
|
||||||
|
|
||||||
ramprct = psutil.virtual_memory().percent
|
if use_psutil:
|
||||||
if ramprct > cmp:
|
ramprct = psutil.virtual_memory().percent
|
||||||
log("{prct} RAM usage, dumping temporary caches!".format(prct=ramprct),module="debug")
|
if ramprct > cmp:
|
||||||
invalidate_caches()
|
log("{prct} RAM usage, dumping temporary caches!".format(prct=ramprct),module="debug")
|
||||||
|
invalidate_caches()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user