File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -55,4 +55,16 @@ async def update_db(position):
5555
5656def begin ():
5757 position = init_db ()
58- asyncio .create_task (update_db (position ))
58+
59+ # After initializing the database, we need to start a non-blocking task to update it
60+ # every second or so. If an event loop is already running, we can use an asyncio
61+ # task. (This is the case when running via `shiny run` and shinylive.) Otherwise, we
62+ # need to launch a background thread and run an asyncio event loop there. (This is
63+ # the case when running via shinyapps.io or Posit Connect.)
64+
65+ if asyncio .get_event_loop ().is_running ():
66+ asyncio .create_task (update_db (position ))
67+ else :
68+ from threading import Thread
69+
70+ Thread (target = lambda : asyncio .run (update_db (position )), daemon = True ).start ()
You can’t perform that action at this time.
0 commit comments