A problem with ui.in_background and console.alert - help need asap :) [FIXED]
GitRepo with the app is here: https://github.com/Vik2015/appbug
When you click some zip file in the TableView, it asks you if you are sure you want to unzip this file. But looks like ui is not waiting for the function to finish and just returns None from it. Any ideas why and how to fix it? Thanks
omz last edited by
When you decorate a function with
@ui.in_background, it will always return
None. This is by design – the entire point of
ui.in_backgroundis basically to return immediately, without blocking, and when it returns, the result of the actual function call is not yet known.
In your case, I would recommend moving the
ask_unzipaction into the
Appclass (don't forget the additional
selfparameter), and then calling some kind of
do_unzipmethod if the alert comes back with a confirmation. So basically, you'd split the
unzipmethod in two, one that just shows the alert, and the other one that does the actual unzipping, and which you call separately when the alert returns in the background. I hope that makes sense.
@omz, if I understand you right, I should have like three methods,
ask_unzipand if user presses "Yes" it will call
Okay, I think I finally got it.
do_unzipshould have decorator
@ui.in_backgroundand other functions should not. Now it runs just fine. Thanks :)