currently I have a generator function that is called by a charting program in the javascript side of my webapp.
I am using the @stream_with_context decorator but that unfortunately only gives me the context when the generator begins running but I want the context constantly updated as I have a boolean variable that the generator needs to know that is constantly changing and I am updating it in the session dictionary.
I would like to be able to access this updated session in the generator. Or if there is any way I can communicate a boolean variable to the generator that would be fine too.
I don't care how it gets there I just thought using session would be the easiest.
Status Update: I have still not found a way to do this... It seems pretty simple but there is nothing on the internet about requesting the current context.
Flask
@app.route('/plotter', methods=['GET', 'POST'])
def plotter():
#some setup in here
@stream_with_context
def generate_data():
while True:
if(session['bool']):
#do something
@app.route('/elsewhere')
def bool_status():
session['bool'] = #new_val <---- this where the val is updated... in another view called by a button.
Javascript
// this how the generator is called
const source = new EventSource("{{url_for(source)}}");