-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
Seperate Client and ClientAsync #186
Seperate Client and ClientAsync #186
Conversation
why duplicate the code? you can keep a client instance inside your async client and call the client methods from the async methods. |
Just to prevent more missunderstandings:
|
If it is about the return values, yes they are None at the moment, because I didn't know what the best way would have been to say "This async request is timeouted", since the client version doesn't have such a thing as well. What I found was the What I can do is replacing these Nones with something like:
We could also create own error classes and raise them as well. |
What if we make an abstract Class |
I don't see an advantage there, it just adds complexity. Why not just make a |
|
Remove duplicated codelines in client_async and left the usable async methods, so that Client_async is extending the Client class to be most SOLID and DRY.
Remove blank line
Perhaps a second thought from @spreeker would be nice as well, what the best way would be. |
I'm not sure what you are trying to accomplish here. This PR just removes a couple of calls from the client class. I think @spreeker probably thinks the same, just keep the client class as a thin wrapper around all the lower-level library function calls. Then implement your async code in a separate module which calls the methods implemented in the client class. Keep all the async code in the async module. I described this before, but maybe I was not clear. I don't want to introduce any backwards-incompatible changes and I also want to keep exposing the original lower-level functions (like client. as_ab_read). As also said before, both @spreeker and I are not convinced that adding async support to python-snap7 is a huge win, but we are open to your contributions. if you manage to add async support in a backwards-compatible way, then why not. But this is becoming quite a time-consuming thing now, I'm doing this in my spare time which is sparse. You now have 3 pull requests open that are all not finished, they don't really improve the codebase. If you want to pick up issues (which I still encourage you to do) then do so but pick up one task at a time and try to understand our concerns also. |
And I told you, that an async wrapper won't work, because the async methods in I will try to explain the last time, why I won't wrap async methods from Example
This kicks off an snap7 async request. The value in result is the value where
This method just checks, if a Snap7Error was thrown or not afaik. So either the Thread has been to slow and the invalid value in The invalid result may be accepted as plausible result (depending on what's inside) and returned to upper methods. After the program returns, you haven't got anything in your hand to fix that.
If I would use this method inside an async wrapper method, I had to deal with incorrect values. And I can't catch them. I offered a solution/way to expand this into an async background with python-inbuilt stuff and it works and was merged into master. To use it in an intuitive way and to stay DRY I chose to keep the names and overwriting the symantic here. It may not be a good way in projects with higher complexity and even more hierarchies, but this isn't the case in python-snap7 and propably will never be (either a request is sync or async). While working on #180 you mentioned there:
So I had to stop in #180 and #178 (because I won't invest time and in the end I have to rework everything on a new base) and tried to provide solutions here in #186. The intricacy about this is:
So in my opinion there aren't many ways:
I can't imagine another way without violating one of these upper listed points. Perhaps we are talking at cross purposes. Perhaps somebody else knows a better way. But as long as this "core-problem" isn't solved, I won't contribute async stuff anymore. |
Now I think a bit longer about it, the issue with the current as function implementation in |
Correct. And snap7 offers 3 solutions to check if the data is ready:
These are your possibilities to check if the Job is done/the data is ready in a snap7-way. But this would cost your "just-wrapper" style, because a user should choose on their own which one of this 3 solutions they would like. And like I said, doing something else while waiting for the job to be done in a "sync-way" (using functions as methods) is either inefficient or complex. Not so with asyncio. EDIT: But this is a thing which should be discussed in #164 while we are here still discussing about code style, the does and don'ts. |
So these 3 calls should be implemented in |
It seems that this is an ToDo, but for another PR, including tests (especially when pointers are returned, I don't know how the garbage collector handles them) which somebody else may contribute. When that PR (fixing the as_checking methods) is through, you and @spreeker have to decide if:
or
Then I would change stuff as you have chosen and may contribute more async tool_stuff, if you like. Deal? |
The garbage collector will not touch that object as long as there is a reference, which we are keeping. I don't have the time nor the need to add those functions at the moment, so let's see if someone will implement them over time. |
Make seperate Class ClientAsync, independent from Client class, like mentioned in #180