Terminating apps (AppDaemon 4.0.4)

I need to terminate apps. In AppDaemon 4.0.3 I used exit() which worked fine. In AppDaemon 4.0.4 exit() terminates the entire AppDaemon with all apps.

I could use self.stop_app(self.name) but it does not stop the app immediately (that means the code in the following lines of the function is still executed).

A workaround is to leave all functions manually. But this would require many additional code lines for condition checking.

What is the best way to exit an app? Or is there a way to get the old behavior of 4.0.3 with in the new 4.0.4?

Thanks

I found a solution: Raising an error instead of exit() terminates only the one app.

Hi @daniel2,

I learned by experience that raising an error will terminate the app if it is raised on the initialize function. However, if it is raised inside a callback function from listen_state or listen_event, then the application will not terminate, it will only crash. So you can keep.calling with the same state or event and it will keep crashing.

Cheers,
Xavi M.

That is a good point. Now I use self.stop_app(self.name) followed by raise RuntimeError(""). raise stops the execution of the code in the current function and stop_app terminates the app with all its callbacks. So far, that works for me.

1 Like