We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d88bb3 commit 32b79eaCopy full SHA for 32b79ea
examples/model-score/scoredata.py
@@ -55,4 +55,16 @@ async def update_db(position):
55
56
def begin():
57
position = init_db()
58
- asyncio.create_task(update_db(position))
+
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()
0 commit comments