__init__.py 1011 B

123456789101112131415161718192021222324252627282930313233343536
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. import logging
  3. logger = logging.getLogger('searx.shared')
  4. try:
  5. import uwsgi
  6. except:
  7. # no uwsgi
  8. from .shared_simple import SimpleSharedDict as SharedDict, schedule
  9. logger.info('Use shared_simple implementation')
  10. else:
  11. try:
  12. uwsgi.cache_update('dummy', b'dummy')
  13. if uwsgi.cache_get('dummy') != b'dummy':
  14. raise Exception()
  15. except:
  16. # uwsgi.ini configuration problem: disable all scheduling
  17. logger.error(
  18. 'uwsgi.ini configuration error, add this line to your uwsgi.ini\n'
  19. 'cache2 = name=searxcache,items=2000,blocks=2000,blocksize=4096,bitmap=1'
  20. )
  21. from .shared_simple import SimpleSharedDict as SharedDict
  22. def schedule(delay, func, *args):
  23. return False
  24. else:
  25. # uwsgi
  26. from .shared_uwsgi import UwsgiCacheSharedDict as SharedDict, schedule
  27. logger.info('Use shared_uwsgi implementation')
  28. storage = SharedDict()