shared_simple.py 714 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. import threading
  3. from . import shared_abstract
  4. class SimpleSharedDict(shared_abstract.SharedDict):
  5. __slots__ = 'd',
  6. def __init__(self):
  7. self.d = {}
  8. def get_int(self, key):
  9. return self.d.get(key, None)
  10. def set_int(self, key, value):
  11. self.d[key] = value
  12. def get_str(self, key):
  13. return self.d.get(key, None)
  14. def set_str(self, key, value):
  15. self.d[key] = value
  16. def schedule(delay, func, *args):
  17. def call_later():
  18. t = threading.Timer(delay, wrapper)
  19. t.daemon = True
  20. t.start()
  21. def wrapper():
  22. call_later()
  23. func(*args)
  24. call_later()
  25. return True