Rewritten library using asyncio#1048
Rewritten library using asyncio#1048albaintor wants to merge 11 commits intohome-assistant-libs:masterfrom
Conversation
|
Sorry pressed wrong button. I like the effort, but i wonder how we can handle this in a non breaking way for current users of the library. |
|
There is indeed some breaking changes but not so much, only those 2 :
The rest remains unchanged, including all the registrations to the listeners. This is a great benefit I think especially for HA which works only with a single event loop in a single thread. Also the new implementation is more efficient in performances / CPU usage. Maybe you could create a forked branch (with dedicated releases, eg |
|
I just wanted this to get better support for happyeyeballs connection of sockets. Are you still interested in trying to get this further? |
| # first 4 bytes is Big-Endian payload length | ||
| read_len = struct.unpack(">I", data[0:4])[0] | ||
| data = data[4:] | ||
| data = data[:read_len] |
There was a problem hiding this comment.
There is no guarantee this data is the full payload. It could haven been split in chunks. So this need to accumulate as much as it need.
I think a standard asyncio task with just recv calls would be easier. It would also reduce the rather huge diff on this file.
Hi,
I rewrote the library using asyncio instead of threads. I had issues with the old behaviour and it was not suitable to use with an async program.
I tested it successfully on my side. Of course there are some breaking changes :
Instead of calling
waitmethod, we use the connect method directly like this :As you can see the code is much more simpler as a lot of work is performed directly in standard wrappers of asyncio.