Closed matan-h closed 9 months ago
As the sys.excepthook
documentation says, it's called "just before the program exits". But this isn't applicable when Python is embedded inside another program, because Python doesn't own the main loop and it doesn't decide when to exit the program. Instead, in Chaquopy's case, it converts the Python exception into a Java exception and lets the calling code decide what to do with it.
Of course, if you're calling some code that you expect to throw an exception, then you can always wrap it in a try
block and handle the exception however you want. So how would sys.excepthook
be useful in the context of BeeWare?
Of course, if you're calling some code that you expect to throw an exception, then you can always wrap it in a
try
block and handle the exception however you want. So how wouldsys.excepthook
be useful in the context of BeeWare?
thats exactly what I do now in my brbug library : I have a "@brbug.catch_beeapp" on the class which do "try/except" on each method. but it could be easier for the user to call brbug.install
to install excepthook.
I see; that looks like a useful tool. But since sys.excepthook
is only relevant in standalone Python processes, I think the way you're currently doing it is the best option.
However, there might be a simpler way of dealing with the .pyc source code issue, because you can just disable .pyc compilation using the build_gradle_extra_content
option. See:
Thanks, that's cool, I didn't know about it. (and I'll mention it in my library), and it seems like kivy doesn't implement it either.
Maybe it would be wise to implement it in toga_android
(in the main_loop) or in briefcase-android-gradle-template
(e.g. a default "try/except" in the mainactivity), since they are intended to a main python process, and the java there just to allow the python to run.
The main_loop
method isn't actually a main loop at all on Android – it has that name for compatibility with the other platforms, but it just returns after initializing the app. iOS is similar.
All the event handlers are called from Android's own main loop, so the closest thing to what you're looking for would be the "Error in handler" blocks like this one.
When I try to use
sys.excepthook
it looks like it's not being called. For example, in this code:I get back directly the crash without the excepthook:
does chaquopy have any future plan to support
sys.excepthook
?