I am trying to use python concurrent.futures.ThreadPoolExecutor() to run multiple instances of “ingestion” function for given metadata.
“final” is a list of tuples that holds the values of arguments for the function called.
As per the existing discussions, I installed streamlit==1.12.0 to use add_script_run_ctx()
Original python script without streamlit dependency (was working fine):
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(lambda f: ingestion(*f), final)
Code snippet:
from streamlit.runtime.scriptrunner import add_script_run_ctx
with concurrent.futures.ThreadPoolExecutor() as executor:
abc = executor.map(lambda f: ingestion(*f), final)
add_script_run_ctx(abc)
Expected behavior:
The code should enter the “ingestion” function and iterate through tuples present in the “final” list.
Actual behavior:
Thread ‘ThreadPoolExecutor-8_0’: missing ScriptRunContext
‘generator’ object has no attribute ‘streamlit_script_run_ctx’
"""
streamlit==1.12.0
"""
import time
import concurrent.futures
import streamlit as st
from streamlit.runtime.scriptrunner import add_script_run_ctx
final = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
def multip(a, b):
time.sleep(a)
return a * b
if __name__ == '__main__':
if st.button('run'):
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
results = executor.map(lambda f: multip(*f), final)
for t in executor._threads:
add_script_run_ctx(t)
res = []
for value in results:
res.append(value)
st.write(f'res: {res}')
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.