Resetting anvil server function call

I am running programs implemented on Google Colab using anvil works.

I am trying to find a way to check if the Google Colab programs are runnning or not, since it will be running only when I switch it on. So, I want to have a message to users, when the Google Colab programs are running, and when it is not, so that users will know when to use my web app and when it cant be used.

So, I defined anvil.server.callable function inside the Google Colab notebook, which returns 1.

def query_start():
return 1

And I created an if else statement on anvil client code as below:
if((anvil.server.call(‘query_start’) ):
self.label_19.text = “The program is ready for use.”
else:
self.label_19.text = “The program is not ready for use as the servers are switched off.”

But, I find that once the Google Colab program with the function query_start is run, and later switched off, the anvil code still gets the value as 1 for anvil.server.call(‘query_start’). Is it storing the value in some temporary variable? How can I reset the value of anvil.server.call(‘query_start’) everytime the anvil webapp is run?

Are you seeing the error when you shut off the Colab server while still running Anvil app? Does the function call on the Client side only get called when the Form starts up?

If the answer to both is yes, the problem would be that the block of code you shared isn’t getting run when the server is shut off. An easy (though maybe not ideal) solution would be to setup a timer to run the check every so often.

If that isn’t true, could you share a clone link so we can see what’s going on with more detail?

What I do is this:

I shut off the Colab server, and then I load the webapp by refreshing the page. So, I expect the message to be: The program is not ready for use as the servers are switched off, but I get the message: The program is ready for use.

The function call on the client side only gets called when the form starts up which I guess is same as reloading the page, or navigating the url for the webapp.

I agree that the block of code which I shared isnt getting run when the server is shut off. In that case, what value does Anvil take when I call the server function by loading the page? Or to be precise, what will be the value of (anvil.server.call(‘query_start’) where query_start is the function I have defined in Google Colab?

Do you have a function with the same name defined in a server module?

I have defined it in Google Colab code and wrapped it with anvil.server.callable inside the Google Colab code. Is that what you are looking for?

If you have the same function define in two places, Anvil will pick one (almost) randomly and execute it.

I was wondering if you accidentally defined a callable function with the same name also in a server module, and the function is available even when that notebook is not running.

Also, make sure that you don’t have the same notebook running on another computer.

I would also add a print after that function is called, just to make sure that the function call is actually executed.

1 Like

It is difficult to prove this, but I also feel that Anvil sometimes sends requests to dead uplinks and the request is lost in space. To overcome this, I’m changing the function names after major changes; myfunction_v2 etc.

As a workaround for your problem, you can create a data table in Anvil with 2 fields; “FunctionName”, “LastActive” (datetime)
Your uplink code (Google Collab) periodically updates the LastActive field.
Then, at your frontend code you can check this field and decide if the uplink is running or not.

I hope Anvil has a better way and I’d like to hear that as well :smiley:

1 Like

If we had the dashboard I have requested here, this problem would not exist :slight_smile:

1 Like

In the meantime, for business-critical services, it may make sense to create such a dashboard, using additional table(s) to log new Uplink connections and the functions each connection offers. Connections would be tested periodically (scheduled background task) to see whether the Uplink is still up, so that dead connections could be removed from the table.