Hello, I've been using a separate thread to run a long computation process in my application using solara.use_thread. The idea is to keep the UI responsive and prevent server disconnects. I've attached a simplified flow diagram of my setup. However, I'm experiencing inconsistent behavior. Sometimes the process runs perfectly for a long time, but at other times, it crashes almost immediately or after a short while. Here's the flow: +------------------+ +-----------------+ | ModelControl | --> | thread_function | | (Start/Stop Btn) | | (Model Logic) | +------------------+ +-----------------+ | | V V +------------------+ +-----------------+ | solara.thread | | CNN Execution | | (Separate Thread)| | (Model Logic) | +------------------+ +-----------------+ | V +------------------+ | StatusBar | | (Display Status) | +------------------+
Hi! What do you mean by crashing ? And can we see a simplified version of the code?
Sorry what I mean by crash is I get a server disconnected that looks like the solar.dev server disconnected notification. running = solara.reactive(False) status_message = solara.reactive("Ready to start.") timer_value = solara.reactive(0) start_time = solara.reactive(None) elapsed_time = solara.reactive(None) model_status = solara.reactive('Waiting') thread_running = threading.Event() @solara.component def ModelControl(running, status_message, start_time): def start_model(): running.value = True start_time.value = datetime.datetime.now() thread_running.set() def stop_model(): thread_running.clear() running.value = False status_message.value = "Model stopped by user." if running.value: return solara.Button(label="Stop Execution", on_click=stop_model) else: return solara.Button(label="Start Model", on_click=start_model) @solara.component def CombinedThread(running, timer_value,t1, elapsed_time, status_message, available_dates, selected_coordinates, selected_country, model_status): def thread_function(): while True: thread_running.wait() # Wait until signaled to start. if available_dates.value and running.value: status_message.value = "Model is running..." timer_value.value +=1 final_df = CNN(model_status, t1, elapsed_time, dates_list=available_dates.value, coordinates=selected_coordinates.value, country=selected_country.value ) if model_status.value == "Model run complete!": status_message.value = "Model run complete!" timer_value.value -=1 available_dates.value = None thread_running.clear()# Signal the thread to stop. running.value = False elif not available_dates.value and status_message.value != 'Model run complete!': status_message.value = 'Requires Date Selection' running.value = False timer_value.value = 0 thread_running.clear() result = solara.use_thread(thread_function, dependencies=[running.value]) @solara.component def Page(): ModelControl(running, status_message, start_time) CombinedThread(running, timer_value, elapsed_time, status_message, model_status)
I've modified it such that it runs, but it doesn't stop the server
do you have an error message why it stops the server? also, i'm not sure your logic is correct, and I don't think you need the threading.Event
@maartenbreddels I wanted to thank you for your response to this, I ended up getting fulltime employment on top of the internship I am building this for so I got quite busy. It still has this bug but to clarify its on huggingface and runs perfectly fine locally. I can't seem to figure what the issue is there so I may just to have to live with it. I'll be sharing it shortly on the showcase channel.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
For logged on users I want to give usersFor logged on users. I want to give users the flexibility of saving the results (basically a nestedWell I am definitely on the right trackWell, I am definitely on the right track hahaha. This is exactly the approach I took.another question i just want to combineanother question , i just want to combine cross filter with map (leafmap) however I couldn't make i2 No if you put in a top level dict not2) No, if you put in a top level dict (not reactive) in a module, every user sees the same dictionarIf I ve setup an app with multiple pagesIf I've setup an app with multiple pages using Solara's routing, is there an easy way to redirect a Thank you for your answer but nextThank you for your answer, but next question, why display(button) from widget on solara component doBlender with Solarawould be very happy to be a guinnea pigwould be very happy to be a guinnea pig 😄Which version of lab running pip installWhich version of lab? running !pip install will install it in the kernel environment, if the lab serThanks how could I programatically setThanks ! how could I programatically set theme from Python side ?it seems to be functional not sure Iit seems to be functional. not sure I understand the downside of my current approach. but fixing any3 what s the best way to implement `push3. what's the best way to implement `push notification` ? is it something like this ? and is it run 2 when I create a module level reactive2. when I create a module level reactive var like `x = solara.reactive(None)`, is it application widcouple of questions around sessioncouple of questions around session management: 1. I found Solara manages session via cookie which isI m not sure what you mean but changingI'm not exactly sure what you mean, but changing the value from the backend would look something likhey solara team looking into statehey solara team looking into state documentation. It seems solara.reactive is session based as in if