Interruptable Server Calls

I developed this short dependency that allows you to make “Low Priority Server Calls”.

By default, Anvil puts all additional server calls in a queue while the current call is finished. However, these low-priority calls will automatically be interrupted if any new server call is made. This can be especially useful while making calls in the background.

Clone link to dependency Anvil | Login

Using it is simple. You just need to import it in your code like this

from Interruptable_Server import low_priority

And then make a server call like this

low_priority.call('My_Server_Functions',param1,param2)

After that, if you make any additional calls, the low-priority call will be automatically suspended and return the value None.

Here is a example of it showing a long server call (10+ seconds) that can be interrupted by another urgent call.
Anvil | Login

Note

  • This dependency was built in a short period of time. Please carefully test it before usage in production

  • This dependency does not actually stop the execution of low-priority calls in the backend (Once the request is sent to the server, there is no way to take that back). It just prevents blocking of other server calls on frontend.

  • Always add a conditional statement with low priority calls as it may return None if interrupted

value = low_priority.call('My_Server_Functions',param1,param2)
if value != None:
   #Do something with the value
4 Likes