Closed coolboyqu closed 2 weeks ago
Hi @coolboyqu IIUC you could do something like this:
import gradio as gr
def update_state(request: gr.Request):
session_hash = request.session_hash
# do something with session_hash
return 123
with gr.Blocks() as demo:
s = gr.State()
demo.load(update_state, None, s) # at page load, s will store "123"
demo.launch()
if this does not answer your question, please provide more details and a code snippet that explains what you're trying to do. You can ask in this thread, or preferably, for general questions like this (that are not feature requests or bug reports), please ask in our Discord server. (I'll close this issue)
Hi @coolboyqu IIUC you could do something like this:
import gradio as gr def update_state(request: gr.Request): session_hash = request.session_hash # do something with session_hash return 123 with gr.Blocks() as demo: s = gr.State() demo.load(update_state, None, s) # at page load, s will store "123" demo.launch()
if this does not answer your question, please provide more details and a code snippet that explains what you're trying to do. You can ask in this thread, or preferably, for general questions like this (that are not feature requests or bug reports), please ask in our Discord server. (I'll close this issue)
I'm sorry I didn't describe my problem clearly. What I meant was to find this session based on its unique identifier. For example, I recorded a row of data {cookie: 'abcde', session identifier: [1,2,3,4,5]} in the database. Before updating this database cookie to a new value, I would like to modify the State of several session operations with cookie 'abcde' based on [1,2,3,4,5]
Its still not clear to me, what is this "session identifier" here?
Its still not clear to me, what is this "session identifier" here?
Similar to session hash, a value which can uniquely mark the session.
Ok so I think my code snippet should provide a solution, right? You can access the session_hash and then look it up a db from within your function?
Can the State of an opened session be modified based on the session hash or any unique session identifier?I want to record the session ID and proactively change the State corresponding to all sessions when user data changes.Is this currently possible?
Of course, I can also actively search the database every second to observe whether the corresponding user data has changed, but this may consume a lot of network resources in situations with a large number of users.