added timeout

This doesn't work yet
This commit is contained in:
Pranav Jerry 2021-11-14 19:57:35 +05:30
parent caeb042612
commit 183ce16eca
No known key found for this signature in database
GPG Key ID: F1DCDC4FED0A0C5B
3 changed files with 13 additions and 4 deletions

View File

@ -42,4 +42,4 @@ given below.
#
# In case you forgot to change the version, skip the number
# and put the next number in the next commit.
__version__ = "0.5.1a0.dev3"
__version__ = "0.5.1a0.dev4"

View File

@ -29,6 +29,7 @@ examples.
import subprocess
from pathlib import Path
from gi.repository import GObject
from dasbus.connection import SystemMessageBus
from dasbus.loop import EventLoop
@ -145,10 +146,12 @@ class NetworkLoop(NetworkD):
def wait_until_routable(self, timeout=0):
"""
wait until timeout in milliseconds and returns True when any
network interface is shown routable by networkd
Wait until timeout in milliseconds and returns True when any
network interface is shown routable by networkd. Does not wait
for timeout if timeout==0
"""
self.wait_for_change("AddressState", self.on_addressstate_change)
self.setup_timeout(timeout)
return self.is_routable()
def wait_for_change(self, name, function):
@ -167,6 +170,11 @@ class NetworkLoop(NetworkD):
if self.waitfor in data:
return self.wait_function()
def setup_timeout(self, timeout):
"""setup a timeout"""
if timeout != 0:
GObject.timeout_add(timeout, self.on_timeout)
def on_timeout(self):
"""called by dasbus when a timeout occurs"""
self.loop.quit()

View File

@ -63,7 +63,8 @@ def any_interface_is_routable():
logger.debug("Adding temporary config %s", i)
networkd.add_config(i)
routable = networkd.wait_until_routable()
# timeout = 10 seconds
routable = networkd.wait_until_routable(10 * 1000)
networkd.remove_all_configs()
return routable