-
-
Notifications
You must be signed in to change notification settings - Fork 442
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
Asynchronous version of notify() #396
Comments
It's a great idea! I just have a few comments on this:
So are you looking for something like: import apprise
apobj = apprise.AsyncApprise()
apobj.add('url1')
apobj.add('url2')
await apobj.notify() Or something along those lines? Thoughts? |
I'm envisioning a new method for the existing class: apobj = apprise.Apprise()
[...]
await apobj.async_notify() Note that you can't just change a synchronous function to an asynchronous function and expect existing code to work; writing a function that is both synchronous and asynchronous, in addition to being nontrivial, is considered bad practice. Thanks for the background information; it was very helpful. I've poked around the code to gain an understanding of the execution flow. Currently, for Python 3, it is as follows:
Prior to #304 there was no ThreadPoolExecutor step, so NotifyBase.notify() was actually blocking the event loop. This should have negated any advantage of using asyncio. IMO, the right way to do this would be:
In the long run, dropping support for Python 2 and converting the rest of Apprise to async would simplify things massively, and allow us to reap the full performance benefits of asyncio. |
I can't explain why I did that because it has been a long time and I spent a lot of time working my way through the code but quickly forgot it. The problem we were trying to solve is that the function was blocking the event loop (as you said) and we didn't want it to do that when it was running in an asynchronous context |
I ask because, if I'm not mistaken, there should be no difference between using the event loop's existing executor and creating a new ThreadPoolExecutor instance. 1548ade |
@caronc, I've taken a shot at implementing my proposal. Let me know what you think! |
@YoRyan I added some comments; overall it's amazing how much you've done. 🚀 ⭐ I just had a few questions/concerns (but maybe it's more of just educating me on your thought process). My comments were made to your PR. |
Great work @YoRyan; your fantastic contribution has been merged. 👍 I really appreciate it! ❤️ 🙏 I am going to close this issue now but feel free to open a new one anytime you want. I also won't complain if you do all of the heavy lifting yourself either in a PR like you did here. 😉 |
💡 The Idea
Great project! But I have to say, if you're calling Apprise from a program that is already structured around asyncio (e.g. my new thingy), it's both inefficient and redundant to have to spin up another event loop to call the non-async notify() method.
It would be much better to have direct access to the asynchronous function that Apprise already constructs. Then, you could just await it within your existing event loop.
🔨 Breaking Feature
The text was updated successfully, but these errors were encountered: