Streamlit App- Kill all connection and script when stopped from UI


I recently started using Streamlit and I must say it’s awesome. I have a a question and I am hoping if you guys can help me -

I am working on an app where I allow users to pass SQL query as input parameter and based on the data returned from query it generates couple of charts. It works all good but I recently noticed that even though I stop script execution from UI, python script does not stop execution. Is there anyway to kill all connections when I hit “STOP” from Streamlit app?