mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2024-11-09 23:12:01 +05:30
added timeout
This doesn't work yet
This commit is contained in:
parent
caeb042612
commit
183ce16eca
@ -42,4 +42,4 @@ given below.
|
|||||||
#
|
#
|
||||||
# In case you forgot to change the version, skip the number
|
# In case you forgot to change the version, skip the number
|
||||||
# and put the next number in the next commit.
|
# and put the next number in the next commit.
|
||||||
__version__ = "0.5.1a0.dev3"
|
__version__ = "0.5.1a0.dev4"
|
||||||
|
@ -29,6 +29,7 @@ examples.
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from gi.repository import GObject
|
||||||
from dasbus.connection import SystemMessageBus
|
from dasbus.connection import SystemMessageBus
|
||||||
from dasbus.loop import EventLoop
|
from dasbus.loop import EventLoop
|
||||||
|
|
||||||
@ -145,10 +146,12 @@ class NetworkLoop(NetworkD):
|
|||||||
|
|
||||||
def wait_until_routable(self, timeout=0):
|
def wait_until_routable(self, timeout=0):
|
||||||
"""
|
"""
|
||||||
wait until timeout in milliseconds and returns True when any
|
Wait until timeout in milliseconds and returns True when any
|
||||||
network interface is shown routable by networkd
|
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.wait_for_change("AddressState", self.on_addressstate_change)
|
||||||
|
self.setup_timeout(timeout)
|
||||||
return self.is_routable()
|
return self.is_routable()
|
||||||
|
|
||||||
def wait_for_change(self, name, function):
|
def wait_for_change(self, name, function):
|
||||||
@ -167,6 +170,11 @@ class NetworkLoop(NetworkD):
|
|||||||
if self.waitfor in data:
|
if self.waitfor in data:
|
||||||
return self.wait_function()
|
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):
|
def on_timeout(self):
|
||||||
"""called by dasbus when a timeout occurs"""
|
"""called by dasbus when a timeout occurs"""
|
||||||
self.loop.quit()
|
self.loop.quit()
|
||||||
|
@ -63,7 +63,8 @@ def any_interface_is_routable():
|
|||||||
logger.debug("Adding temporary config %s", i)
|
logger.debug("Adding temporary config %s", i)
|
||||||
networkd.add_config(i)
|
networkd.add_config(i)
|
||||||
|
|
||||||
routable = networkd.wait_until_routable()
|
# timeout = 10 seconds
|
||||||
|
routable = networkd.wait_until_routable(10 * 1000)
|
||||||
networkd.remove_all_configs()
|
networkd.remove_all_configs()
|
||||||
|
|
||||||
return routable
|
return routable
|
||||||
|
Loading…
Reference in New Issue
Block a user