Pergunta

I have problems when some hardware issues appears and my kivy app crashes. For example on Android or iOS. Regular users can't see the log, neither can I.

So, when my application starts, I want to create separate process and somehow look at the status of main application. In case of it's crash I'd like to send error log to my server. So, what is the best way to do this? Maybe another process is redundant and I can make it in more simple way? And how exactly I can catch crash log?...Thanks!

Foi útil?

Solução

TLDR: Use Sentry

There is different kind of crash, and different kind-of tools.

Native crash: usually a segfault, a low level crash that you cannot really do anything. That's what you see on your Play store tab, native crash/art. None of the traceback will talk to you, as you'll see the C trace of your Python interpreter and all the others threads. The user can see a "The application XXX suddenly exited" or something like that. There is tools available to display nicer message in case of a native crash and send it somewhere else, but your application will never recover. The only thing you can do with such tools is to restart it.

Python crash: good news, you can catch them and have comprehensible traceback. I suggest you to look into Sentry. It's opensource, you can install sentry on your server, and when something bad happen in your app, you can send the full traceback to your sentry installation. Very useful.

The integration into Kivy is also very simple:

if __name__ == "__main__":
    import traceback
    from raven import Client
    client = Client('requests+http://XXKEYXX@sentry.yourserver.com/sentry/1')
    try:
        YourApp().run()
    except:
        traceback.print_exc()
        ident = client.get_ident(client.captureException())
        print "Exception caught; reference is %s" % ident

Don't forget to have the INTERNET permission in Android. If there is no internet, it will fail twice on the console. But that's all.

Also, you might want to plug that into the Kivy's ExceptionManager. If the exception happen in the main loop, then you have the possibility to catch it and not quit the app (ignore the exception). Beware if you were doing something important :D

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top