__init__.py 995 B

1234567891011121314151617181920212223242526272829303132
  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('uwsgi.ini configuration error, add this line to your uwsgi.ini\n'
  18. 'cache2 = name=searxcache,items=2000,blocks=2000,blocksize=4096,bitmap=1')
  19. from .shared_simple import SimpleSharedDict as SharedDict
  20. def schedule(delay, func, *args):
  21. return False
  22. else:
  23. # uwsgi
  24. from .shared_uwsgi import UwsgiCacheSharedDict as SharedDict, schedule
  25. logger.info('Use shared_uwsgi implementation')
  26. storage = SharedDict()