Check if uplink server is running

Is there a way to check if an uplink server running before I call it from client? Or might be using try/except? In that last case, is there any specific exception I might can capture, so I know in my client code that the problem related to a not started or stopped server?

I can’t find any related docs (error handling, exception handling, server code…)

thanks!

I found a way to it, the exception type I was missing is anvil.server.UplinkDisconectedError

Here is how to handle a not running / missing server side code and / or find out what other exception might occur

try:
      self.repeating_panel.items = anvil.server.call('get_items')
except anvil.server.UplinkDisconnectedError as err:
      print('No connection to Server!', err)
except BaseException as err:
      print("Unexpected: ", err, type(err))

It would be great if we can find all exception and error handling codes in the docs. Searching for “anvil.server.UplinkDisconnectedError” gives no results at all.
However, you can find it in the API reference:

1 Like

You may already know this, but for anyone else reading later, catching BaseException instead of Exception (or something more explicit) will cause a program to not respond to KeyboardInterrupt and you may not be able to gracefully shut down your python instance.

Of course, I don’t think you will run into a KeyboardInterrupt on the anvil server, so in this limited case, nothing really needs to change.

2 Likes

Thanks for the extra info. In this example the BaseException is there to catch all unhandled exceptions, so you can do whatever you want. Also it helps to find out what sort of error could happen. (in my practice sometimes the docs also missing some exceptions which might occurs)