I want to run apps from my app folder which uses custom_py_package1 and custom_py_package2. Now that all works fine but Iβd like my apps to detect changes in my custom packages without restarting the app. How do I achieve this?
Hi @mr-bjerre, thanks for your question. By default Streamlit only watches modules within the directory of the main script file. In your case, that would be app.
Nevertheless, Streamlit also watches modules in the PYTHONPATH. So setting the PYTHONPATH to include the modules you want to track should help you.
@monchier is this currently working? Iβm modifying a function foo inside $ROOT/mypackage/func.py
and my streamlit app file is in $ROOT/utils/streamlit_main.py
When doing
export PYTHONPATH = $ROOT/mypackage/func.py
streamlit run $ROOT/utils/streamlit_main.py
If I modify function foo inside func.py, streamlit doesnβt detect the changes in the main app.
It seems that the issue was not importing directly the function, but rather importing the module.
What Iβm currently doing is the following:
import inspect
import os
import streamlit as st
from streamlit import session_state as st_session
from mypackage.module import foo, bar
def monitor_func(*args):
if 'monitor' not in st_session:
st_session['monitor'] = set()
for func in args:
path = inspect.getsourcefile(func)
st_session['monitor'].add(os.path.dirname(path))
os.environ['PYTHONPATH'] = ':'.join(list(st_session['monitor']))
monitor_func(foo, bar)
foo()
bar()
Then changes in foo and bar are detected in the main app.
But if I do:
import inspect
import os
import streamlit as st
from streamlit import session_state as st_session
from mypackage import module
def monitor_func(*args):
if 'monitor' not in st_session:
st_session['monitor'] = set()
for func in args:
path = inspect.getsourcefile(func)
st_session['monitor'].add(os.path.dirname(path))
os.environ['PYTHONPATH'] = ':'.join(list(st_session['monitor']))
monitor_func(module.foo, module.bar)
module.foo()
module.bar()
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking βAccept allβ, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.