Skip to content

Commit

Permalink
feat: avoid calling get_running_loop when resolving ServiceInfo (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Sep 9, 2023
1 parent dac5d4b commit 33a2714
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/zeroconf/_services/info.py
Expand Up @@ -263,11 +263,11 @@ def properties(self) -> Dict[Union[str, bytes], Optional[Union[str, bytes]]]:
assert self._properties is not None
return self._properties

async def async_wait(self, timeout: float) -> None:
async def async_wait(self, timeout: float, loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
"""Calling task waits for a given number of milliseconds or until notified."""
loop = get_running_loop()
assert loop is not None
await wait_for_future_set_or_timeout(loop, self._new_records_futures, timeout)
await wait_for_future_set_or_timeout(
loop or asyncio.get_running_loop(), self._new_records_futures, timeout
)

def addresses_by_version(self, version: IPVersion) -> List[bytes]:
"""List addresses matching IP version.
Expand Down Expand Up @@ -722,6 +722,9 @@ async def async_request(
if self.load_from_cache(zc, now):
return True

if TYPE_CHECKING:
assert zc.loop is not None

first_request = True
delay = _LISTENER_TIME
next_ = now
Expand All @@ -743,7 +746,7 @@ async def async_request(
delay *= 2
next_ += random.randint(*_AVOID_SYNC_DELAY_RANDOM_INTERVAL)

await self.async_wait(min(next_, last) - now)
await self.async_wait(min(next_, last) - now, zc.loop)
now = current_time_millis()
finally:
zc.async_remove_listener(self)
Expand Down

0 comments on commit 33a2714

Please sign in to comment.