on master help sign in
[mod] searx.shared: minor tweaks

searx.shared.shared_abstract.SharedDict inherit from abc.ABC searx.shared.shared_uwsgi.schedule can schedule multiple functions without issue

commita0c8b413a610e8cde49dbb321ba17b16200eb92f authorAlexandre Flament <alex@al-f.net> dateMon 11 Jan 2021, 18:44 (6 years ago) parent87bafbc
2 files changed+10−3
searx/shared/shared_abstract.py+7−1 searx/shared/shared_uwsgi.py+3−2
searx/shared/shared_abstract.py+7−1
@@ -1,15 +1,21 @@
11# SPDX-License-Identifier: AGPL-3.0-or-later
2+from abc import ABC, abstractmethod
23
3−class SharedDict:
44
5+class SharedDict(ABC):
6+
7+ @abstractmethod
58 def get_int(self, key):
69 pass
710
11+ @abstractmethod
812 def set_int(self, key, value):
913 pass
1014
15+ @abstractmethod
1116 def get_str(self, key):
1217 pass
1318
19+ @abstractmethod
1420 def set_str(self, key, value):
1521 pass
searx/shared/shared_uwsgi.py+3−2
@@ -44,14 +44,15 @@ def schedule(delay, func, *args):
4444
4545 def sighandler(signum):
4646 now = int(time.time())
47+ key = 'scheduler_call_time_signal_' + str(signum)
4748 uwsgi.lock()
4849 try:
49− updating = uwsgi.cache_get('updating')
50+ updating = uwsgi.cache_get(key)
5051 if updating is not None:
5152 updating = int.from_bytes(updating, 'big')
5253 if now - updating < delay:
5354 return
54− uwsgi.cache_update('updating', now.to_bytes(4, 'big'))
55+ uwsgi.cache_update(key, now.to_bytes(4, 'big'))
5556 finally:
5657 uwsgi.unlock()
5758 func(*args)