Should anvil.server.is_app_online() catch server connection?

What I’m trying to do:
Poll the server to update some client data on a timer, but avoid the dreaded AppOfflineError: Connection to server failed (1006) Error

What I’ve tried and what’s not working:

I’ve tried only polling the server when the application is online using the is_app_online() however, this does not seem to avoid the issue entirely. I could put it in a try/except clause , but I am more posting to better understand what is_app_online does or maybe more what could be the other cause to my error beside the app being offline?

Is it truly just a random connection issue? like stated here:

And if it is, should is_app_online() capture that?

here is the api documentation

is_app_online()

Returns True if this app is online and False otherwise. If anvil.server.is_app_online() returns False we expect anvil.server.call() to throw an anvil.server.AppOfflineError

Code Sample:

if anvil.server.is_app_online():
      self.table.search() # This is a client readable table

Hi @anthonys,

You can use anvil.server.is_app_online() on the client to check if the app is online. Since that method returns a boolean, the code sample you include should work fine. The table won’t be searched if the app is offline. When are you experiencing the AnvilOfflineError?

Hello @brooke !

This is the exact code:

  def server_sync(self):
    if not self.syncing_flag and anvil.server.is_app_online():
      self.syncing_flag = True
      result = True
      if self.table is None:
        result = self.load_table() #THIS IS NOT BEING REACHED BECAUSE self.table is defined
      with anvil.server.no_loading_indicator:
        if result:
          self.data = self.table.search() #THIS IS WHERE THE ERROR IS RAISED
          self.serialize_data()
      self.syncing_flag = False

Just moved the condition to here:

  def server_sync(self):
    if not self.syncing_flag:
      self.syncing_flag = True
      result = True
      if self.table is None:
        result = self.load_table() #THIS IS NOT BEING REACHED BECAUSE self.table is defined
      with anvil.server.no_loading_indicator:
        if result and anvil.server.is_app_online():
          self.data = self.table.search() #THIS IS WHERE THE ERROR IS RAISED
          self.serialize_data()
      self.syncing_flag = False

See if that helps.

UPDATE: There are still instances where the error is still raised despite the conditional.

Broke it down even further:

  def serialize_data(self):
    if anvil.server.is_app_online():
      self.serialized_data = anvil.server.call_s(self.serialize_call,self.data)

I believe the connection to server error is raised during the server call. At the time the call is made, the app is online, but during the execute of that call, the connection is lost.

Now the task at hand is how to handle this error.


Warning: Thinking out loud section that could be nonsense

There needs to be some memory that is allocated when this error is raised to save the call string and arguments. Then this can be stuck in some timer/while loop (Is a timer just a while loop in the background with a sleep call?) where the call is made again?

Because the call was already made, could I find that return, floating in the ether somewhere, and get it back once connection is established again?