Skip to content

Commit

Permalink
Do not reload installed packages on file change
Browse files Browse the repository at this point in the history
  • Loading branch information
rickythefox committed Mar 22, 2024
1 parent cb89a0d commit e6c3219
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backend/chainlit/config.py
Expand Up @@ -112,7 +112,7 @@
# Specify a custom font url.
# custom_font = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
# Specify a custom build directory for the frontend.
# Specify a custom build directory for the frontend.
# This can be used to customize the frontend code.
# Be careful: If this is a relative path, it should not start with a slash.
# custom_build = "./public/build"
Expand Down Expand Up @@ -340,12 +340,17 @@ def load_module(target: str, force_refresh: bool = False):
sys.path.insert(0, target_dir)

if force_refresh:
# Get current site packages dirs
import site
site_package_dirs = site.getsitepackages()

# Clear the modules related to the app from sys.modules
for module_name, module in list(sys.modules.items()):
if (
hasattr(module, "__file__")
and module.__file__
and module.__file__.startswith(target_dir)
and not any(module.__file__.startswith(p) for p in site_package_dirs)
):
sys.modules.pop(module_name, None)

Expand Down

0 comments on commit e6c3219

Please sign in to comment.