Non blocking process with Shiny for python

90 Views Asked by At

I want to test if Shiny for python app is truly async such that a user can interact with a Shiny for python web app, even when another concurrent user accessing the same app is running a long running process. I thought it is possible but somehow my example code does not indicate so. Is there something wrong with my example code, or my assumption is wrong?

from shiny import App, reactive, ui
from asyncio import sleep

app_ui = ui.page_fluid(
ui.input_action_button("show1", "Show1"),
ui.input_action_button("show2", "Show2"),
)

def server(input, output, session):

    @reactive.Effect
    @reactive.event(input.show1)
    async def _():
        ui.notification_show("Message 1")
        print("sleep 1", session)
        await sleep(5)
        print("sleep 1 finished", session)
        ui.notification_show("Warning message1", type="warning")
    
    
    @reactive.Effect
    @reactive.event(input.show2)
    async def _():
        ui.notification_show("Message 2")
        print("sleep 2", session)
        await sleep(5)
        print("sleep 2 finished", session)
        ui.notification_show("Warning message2", type="warning")

app = App(app_ui, server, debug=False)

My test is as follows:

  1. Run the app in a browser tab as user 1. Press Show1.

  2. Within 5s, run the app in another browser tab as user 2. Press Show2.

Observation: The second tab always show the notification after the first tab finished showing the warning. Similarly, the printout shows similar effect that async is not in action.

0

There are 0 best solutions below