Skip to content
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

Adding Async Capabilities to all decorators #16

Merged
merged 11 commits into from
Jul 24, 2020

Conversation

JonahKr
Copy link
Contributor

@JonahKr JonahKr commented Jul 20, 2020

Hi there 👋
By adding support for async functions, more actions can be handled in a shorter amount of time, especially when using APIs.
The needed additions are very short. I tested all but the Hotword decorator but i assume that it will function the same way.
Using async or normal functions doesn't make any difference on the library side anymore.
I added a hint in the Usage docs but maybe this needs to be referenced somewhere else.

@JonahKr
Copy link
Contributor Author

JonahKr commented Jul 20, 2020

So the failing tests are all regarding type hinting
I could easily add this but it would make it even more unreadable for normal people looking at the docs.

@koenvervloesem
Copy link
Member

Thanks for looking into this! This is definitely a useful addition.

Some remarks:

  • Can you add a simple example app (e.g. an asynchronous version of the time app) that shows app developers how to use asynchronous actions? You can also link to this app in the usage section. I know it's trivial code, but probably not for someone taking their first steps in asynchronous Python.
  • I know that the typing hints are becoming quite unwieldy, but I guess that's the price we have to pay for having an easy-to-use and generic API. Could you still fix the mypy errors? I like to have the typing hints there because they are checked, and we can always drop the signature in the documentation if it becomes unreadable.

@JonahKr
Copy link
Contributor Author

JonahKr commented Jul 22, 2020

@koenvervloesem
So i fixed most of the typehints but recognised that by doing that, running non async functions becomes impossible.
For on_intent its easy... because we just execute the wrapped as an async function and can therefore await any call depending on if its a couroutine or not. For the rest however, i'm currently not sure how to handle this the best way.

Furthermore i wanted to ask if it's okay to import the modules from typing directly instead of having to write typing.before every hint wich become more nested by adding a Awaitable option for all returns.

@koenvervloesem
Copy link
Member

Importing directly from the typing module is fine.

When looking at the code now, and considering the issue with non-async methods, I wonder if we don't make this too complicated to maintain by trying to support both async and non-async methods in the decorators. Maybe we should just drop the possibility to decorate non-async methods? What do you think?

@JonahKr
Copy link
Contributor Author

JonahKr commented Jul 24, 2020

I would support this,especially considering that by enableing async only, the probabilty of people using async libraries and therefore improving parallel processing aswell as more efficient runtime usage. And people don't have to use the features of asyncio if they don't want to. I think this should be decided as early as possible before more apps start using this library.
THe examples wouldn't even need more changes apart from the async keyword.

@koenvervloesem
Copy link
Member

Ok, I agree, let's just do this breaking change now before more people are using the library.

Can you remove the non-async code and typing hints from the parts in the code you touched? I'll fix the documentation, examples and tests in the tests directory afterwards, and then I'll publish a new release.

@JonahKr
Copy link
Contributor Author

JonahKr commented Jul 24, 2020

is there a reason why some End/ContinueSessions are stringified instead of accepting the classes as returns? e.g. Union[ContinueSession, "EndSession"]

@koenvervloesem
Copy link
Member

koenvervloesem commented Jul 24, 2020

These are forward declarations referring to a class that is defined only after this code in the file. It could be that I haven't fixed these everywhere yet. But in the mean time I have moved these simple helper classes forward in the file so that we don't have this problem anymore: 6c42306.

@JonahKr
Copy link
Contributor Author

JonahKr commented Jul 24, 2020

i forgot to pull the new master version and had some issues but they are all resolved now @koenvervloesem.
And the tests are passing now aswell 🎉

@koenvervloesem
Copy link
Member

Thanks, I'll have a look!

@koenvervloesem koenvervloesem merged commit aea281b into rhasspy:master Jul 24, 2020
@koenvervloesem
Copy link
Member

Ok I merged your pull request, tested the example apps and I cleaned up the examples and documentation. Could you take a look at master and let me know if you see some problems? If it looks fine for you, I'll create a new release then.

@JonahKr
Copy link
Contributor Author

JonahKr commented Jul 25, 2020

I went through the docs and it all seems fine. Maybe at least until the next release we should have a banner like section explaining that the async keyword is required now... 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants