How to trigger a background task without holding up the GUI?

How can I trigger a background task without holding up the GUI?

So far I:

  1. Created the server BG function & decorated it with ‘background_task’
  2. Created a server call of it & decorated it with ‘call’
  3. Called (2) from the GUI

I still get the GUI waiting for completion of (2) during the full execution time of (1).

What have I missed?
I know I could do a scheduled job.
But I thought the point of the background decoration was to somehow enable asynchronous calls?

Hi Paul,

Check out the Background Tasks Quickstart!

You define a background task with @anvil.server.background_task (looks like you’ve done this part), and then you launch it by calling anvil.server.launch_background_task(...).

Thnx, but what triggers your call? In my case it is a call from the GUI (to a service function that calls the background function) and it . . holds up the GUI (blue spinning circle).

When you click a button in the UI, you’ll make an anvil.server.call(...) to a server function. The server function is not the same function as the background task – its job is to launch the background task. Again, if you work through the Quickstart hopefully this will become clear. If you’ve tried the Quickstart yourself and it still doesn’t make sense, let us know right away, 'cause that’s a bug :slight_smile:

That’s exactly what I did.
I’ll try and build the exact tutorial app . .

Yep, dumb mistake.
I decorated it background but I didn’t call it as background.
Sorry guys.