Skip to content

Commit 0cc8515

Browse files
committed
use solara task for stepping for a non-threaded version
1 parent 84881e7 commit 0cc8515

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mesa/visualization/solara_viz.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
from __future__ import annotations
2525

26+
import asyncio
2627
import copy
27-
import time
2828
from collections.abc import Callable
2929
from typing import TYPE_CHECKING, Literal
3030

@@ -235,12 +235,12 @@ def save_initial_model():
235235

236236
solara.use_effect(save_initial_model, [model.value])
237237

238-
def step():
238+
async def step():
239239
while playing.value:
240-
time.sleep(play_interval / 1000)
240+
await asyncio.sleep(play_interval / 1000)
241241
do_step()
242242

243-
solara.use_thread(step, [playing.value])
243+
solara.lab.use_task(step, dependencies=[playing.value], prefer_threaded=False)
244244

245245
def do_step():
246246
"""Advance the model by one step."""

0 commit comments

Comments
 (0)