summaryrefslogtreecommitdiff
path: root/searx/engines/__init__.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2022-06-18 07:38:36 +0200
committerAlexandre Flament <alex@al-f.net>2022-06-18 07:39:46 +0200
commit5bcbec9b061b02900dbd8b9751f68bbb5687247d (patch)
tree3b3f79d686e48510e2c053f5fd041934f5687e2b /searx/engines/__init__.py
parenta7b0b2ecbf82f823750f641500085f316cb4edd0 (diff)
downloadsearxng-5bcbec9b061b02900dbd8b9751f68bbb5687247d.tar.gz
searxng-5bcbec9b061b02900dbd8b9751f68bbb5687247d.zip
Fix: use sys.modules.copy() to avoid RuntimeError
use sys.modules.copy() to avoid "RuntimeError: dictionary changed size during iteration" see https://github.com/python/cpython/issues/89516 and https://docs.python.org/3.10/library/sys.html#sys.modules close https://github.com/searxng/searxng/issues/1342
Diffstat (limited to 'searx/engines/__init__.py')
-rw-r--r--searx/engines/__init__.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index ae132f48d..3fb0bcfb1 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -149,7 +149,11 @@ def set_loggers(engine, engine_name):
engine.logger = logger.getChild(engine_name)
# the engine may have load some other engines
# may sure the logger is initialized
- for module_name, module in sys.modules.items():
+ # use sys.modules.copy() to avoid "RuntimeError: dictionary changed size during iteration"
+ # see https://github.com/python/cpython/issues/89516
+ # and https://docs.python.org/3.10/library/sys.html#sys.modules
+ modules = sys.modules.copy()
+ for module_name, module in modules.items():
if (
module_name.startswith("searx.engines")
and module_name != "searx.engines.__init__"