Skip to content

SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.

Fix: use sys.modules.copy() to avoid RuntimeError

Alexandre Flament5bcbec9b061b
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__"