-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apprise is doing I/O inside the event loop #40184
Comments
apprise documentation |
The later versions of Apprise (starting at v0.8.7) adapted |
so is |
Not specifically But i made the async reference a switch, so it can be turned off if require. Edit: I mean I'm leveraging the same thign HomeAssistant is though with asyncio and handling multiple tasks at once. Does this mean that all plugins/adapters to HomeAssistant can't use asyncio going forward? Is there a graceful way it can still be left on? It drastically improves the performance of Apprise (especially when you need to notify more then 1 endpoint. |
I think the problem here is we are going async -> sync -> async. Is there a way to go straight to the async call? |
actually @bdraco pointed out in Discord that at some point, your async code is calling urllib, which is synchronous, hence the upstream detection |
make that |
Unfortunately the
I wasn't aware that |
For now, I can do a pull request to just flat out disable all asyncio so you go from async -> sync if you want? Basically the following code in def get_service(hass, config, discovery_info=None):
"""Get the Apprise notification service."""
# Create our object
a_obj = apprise.Apprise() to this: def get_service(hass, config, discovery_info=None):
"""Get the Apprise notification service."""
# Create our asset object
asset = apprise.AppriseAsset(async_mode=False)
# Create our object
a_obj = apprise.Apprise(asset=asset) |
For point 1, I am not sure if this would resolve this warning. I think the core issue is point 2. I am not the best person to advise you on the changes here, my async knowledge is pretty cursory. And the notification service isn't broken, it's just firing this warning on every notification. If you need some help, you may want to try the #devs_core channel in the HA discord, there are people much more capable than I that watch that channel and may be able to help. |
Just a side note, there are a lot of Apprise services that don't use requests either. Some just use binary protocols such as Growl Notification Transport Protocol (GNTP), Extensible Messaging and Presence Protocol (XMPP), etc. So there are no asynio wrappers for these guys even if i fully converted to What specifically becomes unstable with Home Assistant with |
The sync code is running in the event loop which means that everything has to wait until while data is being read or written on the socket. |
I just tested your proposed fix and the warning still fires 😞 |
Thanks @bdraco for your reply. But since the code stack resides inside the first async call, can it still all be aborted if you had to? I mean at the lowest level you could still call Task.cancel() if you didn't want to wait any longer? Thoughts?
That sucks, you should be bypassing all of the async code with that flag set. Or i have a bug i need to address. |
There is indeed a bug I think. https://github.com/caronc/apprise/blob/784e073eea64d2ee37cc52e7a2391bce35b05720/apprise/Apprise.py#L328 |
It is going to tie up the event loop since there is no code that returns control to the loop while the I/O is happening. If you ran each task in the executor, it would workaround the issue for now.
|
@raman325, No that part is good... async is assigned to each server instance as they're created. I was probably over thinking this feature when i did it. But basically i started it off with that level of granularity (async at a per server being notified basis). Effectively you can have it so some servers run with
@bdraco, fair enough and thank you for all you feedback! |
FWIW when I had |
Something else must be causing the issue because for sure the Keep me posted. |
Here's what I did:
I get both the "I am doing async" message as well as the I/O inside event loop warning. I saw your linked PR and the test does seem to indicate that |
It shouldn't matter, no. They're all inherited from the same plugin base at the end of the day. Can you share your testing steps that you're doing? I am taking a guess at something like...: git clone git@github.com:home-assistant/core.git
pushd core
pip install -r requirements_test_all.txt
py.test -k apprise |
|
thank you for the detailed explanation as to how your doing this! 👍 I tried to do things your way and i might have done something wrong, but this worked: # Repository
git clone git@github.com:caronc/core.git home-assistant.core
cd home-assistant.core
# virtualenv
python3 -m venv .
. ./bin/activate
# requirements
pip install -r requirements_all.txt -r requirements_test_all.txt
# Some missed, but required components:
pip install requests-mock asynctest pytest-sanic sanic
# Then i ran the unit tests and got all green lights:
# I did this after applying the change we discussed.
py.test tests/components/apprise/test_notify.py I'm not sure if I'm missing the key element being tested here, but i was at least able to run the unit tests. I created PR #40213, but it's not identifying anything new that hasn't already been discussed here (or you haven't already tried). |
I tried running the tests without the change and they also pass. It appears running the tests does not trigger the check because I can't even find a log message of that warning. I did a sanity check and tried #40213 (but running This article talks a lot about the different modes and how to call synchronous functions within async and vice versa: https://www.aeracode.org/2018/02/19/python-async-simplified/ In the sync from async section, they reference the Not sure if it's worth it to add another dependency, but it's an option for you |
And here's one using asyncio's |
Thanks for all your research and testing. I'm a bit against pulling in an entire library used for websockets just to use Even if i were to drop all support for I think the best thing is for us to just switch Apprise back to |
🤷🏾♂️ |
FYI @caronc I am still getting this error (I am on 0.115.5 so your change is applied in my installation) |
The problem
HA is reporting that apprise is doing I/O inside the event loop
Environment
Traceback/Error logs
Additional information
I can submit a fix for this, just wanted to report it as an FYISee below threadThe text was updated successfully, but these errors were encountered: