-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid app to crash python agent (#1385)
Co-authored-by: Tamir David <tamirdavid@Tamirs-MacBook-Pro.local>
- Loading branch information
1 parent
0df64e9
commit 793503c
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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')] | ||
|
||
for path in paths_to_move: | ||
sys.path.remove(path) | ||
sys.path.append(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 = [ | ||
'google.protobuf', | ||
'requests', | ||
'charset_normalizer', | ||
'certifi', | ||
'asgiref' | ||
'idna', | ||
'deprecated', | ||
'importlib_metadata', | ||
'packaging', | ||
'psutil', | ||
'zipp', | ||
'urllib3', | ||
'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) |