Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reacton/use_thread issue #403

Open
maartenbreddels opened this issue Nov 27, 2023 · 0 comments
Open

Reacton/use_thread issue #403

maartenbreddels opened this issue Nov 27, 2023 · 0 comments

Comments

@maartenbreddels
Copy link
Contributor

Running this, and hitting compute triggers a keyerror in reacton. The fix is to put str(../) around the last line, but that should not be needed.

import solara
import time


process = solara.reactive(0)

def heavy_compute():
    for i in range(10):
        print("Computing...", i)
        process.value = i
        time.sleep(0.1)
    return 42

@solara.component
def Page():
    compute = solara.use_reactive(False)
    result_using_reactive = solara.use_reactive(None)

    def maybe_do_compute():
        if compute.value:
            result_using_reactive.value = heavy_compute()
            compute.set(False)
    result = solara.use_thread(maybe_do_compute, dependencies=[compute.value])

    solara.Button("Compute", on_click=lambda: compute.set(True))
    solara.Button("Cancel", on_click=lambda: compute.set(False))

    if result.state == solara.ResultState.RUNNING:
        solara.ProgressLinear(process.value * 10)
    if result_using_reactive.value:
        solara.Text(result_using_reactive.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant