Greetings,
I am having an issue with session_state update. The community help on topics related to multiprocessing helped me understand a lot about data sharing across processes.
I am trying to use a session_state to update a st.bar_chart.
but I keep getting this error 'AttributeError: st.session_state has no attribute "data". Did you forget to initialize it? and the app will spin indefinitely until I shut it down.
If I comment out the st.bar_chart line, then everything under the __main__ block will work just fine in seconds.
my ultimate intend is to use the multiprocessing step to frequently pull the data and pass it to the char.
Not sure of why I am getting this error and how I can fix it.
any help is greatly appreciated. below is the code I am running locally on streamlit 1.29, python 3.10.13
def open_file(file_path, out_name): #read data
out_name.df=pd.read_csv(file_path)
if ('data' not in st.session_state):
st.session_state['data']=pd.DataFrame() #empty data frame
st.write(' Bar Char ')
st.bar_chart(st.session_state.data, x='x_label',y='y_label')
if __name__=="__main__":
manager=multiprocessing.Manager()
out_data=manager.Namespace() # namespace used to save new dataset
p1=multiprocessing.Process(target=open_file,args=(data_path ,out_data) )
p1.start()
p1.join()