Skip to content

Commit

Permalink
fix: python app crash in case of dep conflict (#1403)
Browse files Browse the repository at this point in the history
Co-authored-by: Tamir David <tamirdavid@Tamirs-MacBook-Pro.local>
Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
  • Loading branch information
3 people authored Jul 29, 2024
1 parent f6cb2a3 commit cfb27c7
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions agents/python/configurator/lib_handling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import sys
import importlib
from importlib import metadata as md

def reorder_python_path():
paths_to_move = [path for path in sys.path if path.startswith('/var/odigos/python')]
Expand All @@ -11,9 +9,9 @@ def reorder_python_path():


def reload_distro_modules() -> None:
# Reload distro modules, as they may have been imported before the path was reordered.
# Add any new distro modules to this list.
needed_modules = [
# Delete distro modules and their sub-modules, as they have been imported before the path was reordered.
# The distro modules will be re-imported from the new path.
needed_module_prefixes = [
'google.protobuf',
'requests',
'charset_normalizer',
Expand All @@ -29,8 +27,8 @@ def reload_distro_modules() -> None:
'uuid_extensions.uuid7',
'typing_extensions',
]

for module_name in needed_modules:
if module_name in sys.modules:
module = sys.modules[module_name]
importlib.reload(module)
for module in list(sys.modules):
# Check if the module starts with any of the needed prefixes
if any(module.startswith(prefix) for prefix in needed_module_prefixes):
del sys.modules[module]

0 comments on commit cfb27c7

Please sign in to comment.