Skip to content

Provide an asyncio class for service registration#347

Merged
jstasiak merged 15 commits into
python-zeroconf:masterfrom
bdraco:register_without_broadcast
May 5, 2021
Merged

Provide an asyncio class for service registration#347
jstasiak merged 15 commits into
python-zeroconf:masterfrom
bdraco:register_without_broadcast

Conversation

@bdraco

@bdraco bdraco commented May 3, 2021

Copy link
Copy Markdown
Member
  • When using zeroconf with async code, service registration can cause the
    executor to overload when registering multiple services since each one
    will have to wait a bit between sending the broadcast. An asyncio class
    is now available as aio.AsyncZeroconf that implements the following

    • async_register_service
    • async_unregister_service
    • async_update_service
    • async_close

    I/O is currently run in the executor to provide backwards compat with
    existing use cases.

    These functions avoid overloading the executor by waiting in the event
    loop instead of the executor threads.

    The existing Zeroconf object is available as .zeroconf

  • Various tests that do not need to broadcast records no longer do so
    as this slows down the test for something not being tested

@bdraco bdraco force-pushed the register_without_broadcast branch 4 times, most recently from 13d04d6 to 81e3e2d Compare May 3, 2021 19:09
@bdraco bdraco changed the title Provide an AIO wrapper for service registration Provide an AIO subclass for service registration May 3, 2021
Comment thread zeroconf/aio.py Outdated

@jstasiak jstasiak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename the aio module to async or something, I'll imagine it'll be more familiar to the users (and rolls of the keyboard more naturally, at least to me).

All on all I'm really happy to see this change and with few tweaks it should be ready for merging!

Comment thread zeroconf/__init__.py Outdated
Comment thread zeroconf/__init__.py Outdated
Comment thread zeroconf/__init__.py Outdated
Comment thread zeroconf/aio.py Outdated
Comment thread zeroconf/test.py Outdated
@bdraco

bdraco commented May 3, 2021

Copy link
Copy Markdown
Member Author

I think we should rename the aio module to async or something, I'll imagine it'll be more familiar to the users (and rolls of the keyboard more naturally, at least to me).

All on all I'm really happy to see this change and with few tweaks it should be ready for merging!

Python has problems with modules named async.py because of the reserved word. (which is why Home Assistant ended up with https://github.com/home-assistant/core/blob/dev/homeassistant/util/async_.py)

I can call it async_ or asynczc?

@jstasiak

jstasiak commented May 3, 2021

Copy link
Copy Markdown
Collaborator

Huh, that's something that I didn't have in mind at all (the async keyword). What do you think about asyncio? (As in zeroconf.asyncio?) That's what aio stands for anyway after all.

@bdraco

bdraco commented May 3, 2021

Copy link
Copy Markdown
Member Author

Huh, that's something that I didn't have in mind at all (the async keyword). What do you think about asyncio? (As in zeroconf.asyncio?) That's what aio stands for anyway after all.

Lets do that 👍

@bdraco bdraco changed the title Provide an AIO subclass for service registration Provide an asyncio class for service registration May 3, 2021
@codecov-commenter

codecov-commenter commented May 3, 2021

Copy link
Copy Markdown

Codecov Report

Merging #347 (dbf95ff) into master (7816278) will increase coverage by 0.44%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #347      +/-   ##
==========================================
+ Coverage   91.71%   92.15%   +0.44%     
==========================================
  Files           2        4       +2     
  Lines        2678     2780     +102     
  Branches      361      367       +6     
==========================================
+ Hits         2456     2562     +106     
+ Misses        148      146       -2     
+ Partials       74       72       -2     
Impacted Files Coverage Δ
zeroconf/__init__.py 89.59% <100.00%> (+0.28%) ⬆️
zeroconf/asyncio.py 100.00% <100.00%> (ø)
zeroconf/test_asyncio.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7816278...dbf95ff. Read the comment docs.

@bdraco

bdraco commented May 3, 2021

Copy link
Copy Markdown
Member Author

At this point, I'm going to write the changes to use this in

to make sure the use cases are covered.

@bdraco bdraco marked this pull request as ready for review May 3, 2021 23:08
bdraco added 7 commits May 4, 2021 08:50
- When using zeroconf with async code, service registration can cause the
  executor to overload when registering multiple services since each one
  will have to wait a bit between sending the broadcast. An aio subclass
  is now available as aio.AsyncZeroconf that implements the following

    - async_register_service
    - async_unregister_service
    - async_update_service
    - async_close

  I/O is currently run in the executor to provide backwards compat with
  existing use cases.

  These functions avoid overloading the executor by waiting in the event
  loop instead of the executor threads.
@bdraco bdraco force-pushed the register_without_broadcast branch from 53ad3ce to f9f3e68 Compare May 4, 2021 18:51
Comment thread zeroconf/__init__.py Outdated
Comment thread zeroconf/__init__.py Outdated
Comment thread zeroconf/__init__.py
Comment thread zeroconf/__init__.py Outdated
@bdraco

bdraco commented May 5, 2021

Copy link
Copy Markdown
Member Author

Retested, everything working as expected 👍

@bdraco

bdraco commented May 5, 2021

Copy link
Copy Markdown
Member Author

If this looks like its ready, it would be great to get a release so I can start updating packages to use the new async calls.

@jstasiak jstasiak merged commit a41d7b8 into python-zeroconf:master May 5, 2021
@jstasiak

jstasiak commented May 5, 2021

Copy link
Copy Markdown
Collaborator

Very nice work! I'll release this shortly.

@jstasiak

jstasiak commented May 5, 2021

Copy link
Copy Markdown
Collaborator

Version 0.30.0 has just been relased with this change.

@bdraco

bdraco commented May 5, 2021

Copy link
Copy Markdown
Member Author

Thanks!

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.

3 participants