3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 02:19:26 +01:00

auto-t: ead.py: use non_block_wait

This commit is contained in:
James Prestwood 2021-08-13 09:24:40 -07:00 committed by Denis Kenzior
parent 5ebbe07fa6
commit b705a579ad

View File

@ -81,12 +81,8 @@ class EAD(iwd.AsyncOpAbstract):
_adapters = None _adapters = None
def __init__(self): def __init__(self):
tries = 0 ctx.non_block_wait(self._bus.name_has_owner, 20, EAD_SERVICE,
while not self._bus.name_has_owner(EAD_SERVICE): exception=TimeoutError('EAD has failed to start'))
if tries > 200:
raise TimeoutError('IWD has failed to start')
tries += 1
time.sleep(0.1)
self._adapters = AdapterList(self) self._adapters = AdapterList(self)
@ -103,21 +99,8 @@ class EAD(iwd.AsyncOpAbstract):
if not wait_to_appear: if not wait_to_appear:
return list(self._adapters.values()) return list(self._adapters.values())
self._wait_timed_out = False ctx.non_block_wait(lambda s, num : len(s._adapters) >= num, max_wait, self, wait_to_appear,
def wait_timeout_cb(): exception=TimeoutError('EAD has no associated devices'))
self._wait_timed_out = True
return False
try:
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
context = ctx.mainloop.get_context()
while len(self._adapters) < wait_to_appear:
context.iteration(may_block=True)
if self._wait_timed_out:
raise TimeoutError('IWD has no associated devices')
finally:
if not self._wait_timed_out:
GLib.source_remove(timeout)
return list(self._adapters.values()) return list(self._adapters.values())