Not able to access the session context even after using add_script_run_ctx

I want to access the streamlit session variable inside a gstreamer callback function/thread (buffer_dump_prob). In the below code, i have connected buffer_dump_prob to the gstreamer element app sink to receive the data on each buffer and push it into the queue.

I have created a thread context also for that callback function buffer_dump_prob so that i can have access to session variables inside the callback thread.

But when i am trying to access the session variable st.session_state.in_frame side of the thread i am getting missing ScriptRunContext error.

Can somebody please help me to clarify why i am not able to access the session context even after using add_script_run_ctx.

def buffer_dump_prob(self, appsink):
    sample = appsink.emit("pull-sample")
    if sample:
        print("\nAppsink Frame->",self.frame_num ,st.session_state.in_frame )
        st.session_state.in_frame +=1
        buffer = sample.get_buffer()
        # Parsing caps format
        caps_format = sample.get_caps().get_structure(0)
        w, h,format = caps_format.get_value('width'), caps_format.get_value('height'),caps_format.get_value('format')
        # Parsing the buffer into yuv2 image
        buffer_size = buffer.get_size()
        data = buffer.extract_dup(0, buffer_size)
        rgb_converter = RGB_Converter()
        rgb_image = rgb_converter.buffer_to_rgb(data,w,h,format)
        #push the buffer into buffer_queue
        # rgb_image = cv2.resize(rgb_image, (320, 240))
        self.buffer_queue.put(rgb_image,block=False)

    return Gst.FlowReturn.OK


def appsink(self, element):
    appsink = Gst.ElementFactory.make("appsink", "appsink")
    # Set the appsink to emit signals when data is available
    appsink.set_property("buffer-list", True)
    appsink.set_property("emit-signals", True)
    appsink.set_property("drop", True)

    # creating thread context
    generation_thread = threading.Thread(target=self.buffer_dump_prob, args=(appsink,))
    add_script_run_ctx(generation_thread)
    generation_thread.start()

    # Connect the callback function to the appsink's "new-sample" signal
    appsink.connect("new-sample", self.buffer_dump_prob)

    self.pipeline.add(appsink)
    element.link(appsink)
    return appsink

what version of streamlit are you using? ive seen on the forums that β€˜from streamlit.runtime.scriptrunner import add_script_run_ctx’ only works for streamlit <= 1.12.0