Async code in PyScript callbacks?

Hi there, first post here!
I am building by first Panel app using PyScript. Basically a format translator that loads a file into pandas, using pd.read_csv(), and then traverses the rows to generate a proprietary format and download the results to a local file.
Things work OK for small files, but for large files it is very problematic. Particularly the second part, which is entirely in Python and very CPU-intensive. The browser was constantly asking to kill my page and sometimes crashing.
I changed the “translator” engine to use async/await and make periodic calls to await asyncio.sleep(0) to give the browser event loop. I was using the Panel FileDownload and hoping I could give it a handler to the new version, but apparently it seems to require a synchronous callback function - it assumes the function returns the data that will be downloaded, and an async function returns a Handle.
I ended up switching to a regular Button (that can take an async function as an event callback). It would be great if Panel could consider taking async callbacks as arguments to better support PyScript (and web programming in general).

1 Like

Hi @nascif

Welcome to the community. And Thanks so much for your ideas for improvements.

Panel can use async callbacks. Could you help us better understand the issue by providing a minimal, reproducible example of the issue? That will make it much easier to take a next step. Thanks.