john_helt
john_helt8mo ago

Async mo.lazy

hi. Can I use marimo.lazy on async callables (Coroutines) ? Currently, it seems it only works for sync code
5 Replies
Myles Scolnick
Myles Scolnick8mo ago
Yea I don’t think it’s possible today. But you could maybe create a sync wrapper with asyncio.run() We can also look into supporting this - shouldn’t be much effort
john_helt
john_heltOP8mo ago
I tried with asyncio.run, but I get an error: "This cell raised an exception: RuntimeError('asyncio.run() cannot be called from a running event loop')" def sync_code(): asyncio.run(async_calculate()) sync_code()
Myles Scolnick
Myles Scolnick8mo ago
Ah might be the something like asyncio.get_running_loop (Sorry on my phone)
john_helt
john_heltOP8mo ago
no worries, I've tried def sync_code():
loop = asyncio.get_event_loop() loop.run_until_complete(calculate())
sync_code(), but then I get This cell raised an exception: RuntimeError('This event loop is already running')
Myles Scolnick
Myles Scolnick8mo ago
hmm yea maybe we don't support nested event loops. something we can look into. in the meantime, ill make mo.lazy support async