I have a Python script that uses the subprocess module to execute shell scripts. When I run the script directly using Python, it works fine and executes the shell scripts as expected. However, when I integrate the script with Streamlit, the shell scripts are not executed properly.
import time
import subprocess
def run_shell_scripts():
subprocess.run(['bash', 'KtmxSMI_1_Auto_T_B.sh'])
time.sleep(2)
subprocess.run(['bash', 'tmxSMI_1_Auto_T_B.sh'])
if __name__ == '__main__':
run_shell_scripts()
Is the path to the .sh file the full path? I would also check that it is not permission issues that’s blocking the app from executing the shell scripts. If this is not helpful, try debugging the subprocess calls to see if you can capture the output or errors from your shell scripts. Something like this could work (haven’t tested it yet):
Yes, that’s the complete file path. The shell script is located in the same folder. Additionally, it functions properly when executed as a Python script instead of using Streamlit. I’ll attempt the debugging steps you suggested
tmux new-session -d -s Auto_T ; send-keys “python3 Auto_T.py” is inside the .sh file.
To add more context, this setup is running on AWS Ubuntu. Interestingly, the individual shell script works well on its own. Even when I run it using crontab, it still functions as expected. Moreover, when I create a separate Python file and execute it using the ‘python’ command, everything works smoothly.
Yes, it indeed creates a new tmux session named Auto_T, but it doesn’t execute the Python file as expected.
Oh great! Glad you figure it out. Do you mind providing more details on the issue that way if someone runs into this error in future they might find it helpful?
I had a Streamlit app running under a tmux session. This Streamlit app initiated another tmux session and attempted to run a Python file within a .sh file. However, tmux encounters an issue with nested sessions and refuses to send keys in such cases. Therefore, I’ve confirmed that the problem does not lie with Streamlit. I’ve identified the source of the issue and am currently searching for a solution
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.