mirror of
https://github.com/searxng/searxng.git
synced 2025-07-13 00:09:18 +02:00
[enh] add searx.shared
shared dictionary between the workers (UWSGI or werkzeug) scheduler: run a task once every x seconds (UWSGI or werkzeug)
This commit is contained in:
parent
9c581466e1
commit
6e2872f436
7 changed files with 156 additions and 1 deletions
38
searx/shared/shared_simple.py
Normal file
38
searx/shared/shared_simple.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import threading
|
||||
|
||||
from . import shared_abstract
|
||||
|
||||
|
||||
class SimpleSharedDict(shared_abstract.SharedDict):
|
||||
|
||||
__slots__ = 'd',
|
||||
|
||||
def __init__(self):
|
||||
self.d = {}
|
||||
|
||||
def get_int(self, key):
|
||||
return self.d.get(key, None)
|
||||
|
||||
def set_int(self, key, value):
|
||||
self.d[key] = value
|
||||
|
||||
def get_str(self, key):
|
||||
return self.d.get(key, None)
|
||||
|
||||
def set_str(self, key, value):
|
||||
self.d[key] = value
|
||||
|
||||
|
||||
def schedule(delay, func, *args):
|
||||
def call_later():
|
||||
t = threading.Timer(delay, wrapper)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
def wrapper():
|
||||
call_later()
|
||||
func(*args)
|
||||
|
||||
call_later()
|
Loading…
Add table
Add a link
Reference in a new issue