On a very general level you can restart your app like this in the same file or from another file
from your_app import main
while True:
try:
main() # assuming this has a blocking loop as well
except Exception as e:
print(e) # or log it in some way
print("Restarting main")
Even if main terminates without an error it will restart.
You might need to do some clean up beforehand.
More specific to your problem:
There always could be an option that an error is silently suppressed and your code ends or something with the server, which will not show up on the console.