Open AlexMKX opened 1 month ago
Hi there - nothing in AD has changed in this area for several years, and AD itself hasn't had a release in over a year, so if your apps recently stopped working, the cause must be elsewhere.
AD is designed so that all callbacks are tested to see if they are async, and if so, they are called asynchronously by AD using the main event loop, if not they are called synchronously in the Apps thread.
AD api calls are all synchronous to the calling app and run in the app's thread, but call into AD's core which is asynchronous under the hood.
This code has been tested and used by thousands of people for several years so I am reasonably confident there isn't a problem here ;)
You don't give any details go how your apps broke, or any error messages. In your example app, logging the output of the get_state() command would prove that initialize() is running correctly, and that the get_state() was working as expected for instance. Until we have a better idea of what exactly is going wrong it's hard to suggest a way to fix it.
Thank you for the clarifications. It just "have been stopped" when I've rebuilt the container. Perhaps it is because of the new python version or so. I'll try to dig deeper within docker and specific versions to find a root cause. At this moment I just unable to run anything synchronously, so I've been forced to rewrite all my stuff to async. Seems it async is more trendy :)
Definitely trendy but not necessarily better :) AD works either way, but I generally would only use async if a specific library needs it for instance, for everything else the synchronous threaded model works great.
Start simple with some logging like I suggested and build up from there. Good luck!
The first one is caught. PyCharm introduced the asyncio debug feature. In this case it seems event loop is created when doing debug. https://youtrack.jetbrains.com/issue/PY-57667/Asyncio-support-for-the-debugger-EXPERIMENTAL-FEATURE By disabling this feature, the appdaemon apps goes synchronous mode. However, as hass addon it still async. Doing more research.
What happened?
Recently noticed that all my apps have stopped working. By analysing, I found that all appdaemon functions returns coroutines, which means, the python treats them as asynchronous.
Expected result : the sync apps (functions) should be able to call functions synchonously.
Version
4.4.2
Installation type
Python virtual environment
Relevant log output
Relevant code in the app or config file that caused the issue
Anything else?
By stepping within the code, I found that sync_wrapper always gets event_loop
The list of packages in venv