Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not reload installed packages on file change #842

Merged
merged 1 commit into from Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion backend/chainlit/config.py
@@ -1,5 +1,6 @@
import json
import os
import site
import sys
from importlib import util
from pathlib import Path
Expand Down Expand Up @@ -112,7 +113,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 +341,16 @@ def load_module(target: str, force_refresh: bool = False):
sys.path.insert(0, target_dir)

if force_refresh:
# Get current site packages dirs
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