refactor(worker): iterate a sys.modules copy instead of list() (Sonar S7504) (SIENTIAPDE-2214)
This commit is contained in:
@@ -79,8 +79,8 @@ def _get_runtime(runtime: str | None) -> str:
|
||||
|
||||
def _loaded_distribution_versions() -> dict[str, str]:
|
||||
"""Version on disk of every installed distribution whose top-level module is imported."""
|
||||
# list() copies the keys: another thread importing while we iterate would raise RuntimeError.
|
||||
loaded = {name.partition('.')[0] for name in list(sys.modules)}
|
||||
# Iterate a copy: another thread importing while we iterate would raise RuntimeError.
|
||||
loaded = {name.partition('.')[0] for name in sys.modules.copy()}
|
||||
return {
|
||||
dist: importlib.metadata.version(dist)
|
||||
for module, dists in importlib.metadata.packages_distributions().items()
|
||||
|
||||
Reference in New Issue
Block a user