mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 18:35:13 +00:00
module: rework polling in NMUtil.wait_till_connection_is_gone()
time.sleep() does not sleep an exact amount of time, hence, adding up the sleep-times will not give the exact total wait-time. An alternative would be to take a CLOCK_BOOTTIME timestamp (or similar) and determine the elapsed time based on that. Instead, do something different, and use a GLib timeout for polling.
This commit is contained in:
parent
c0b2430144
commit
d2ce509320
1 changed files with 7 additions and 12 deletions
|
|
@ -1060,20 +1060,15 @@ class NMUtil:
|
|||
:returns: True when connection is gone, False when timeout elapsed
|
||||
:rtype: bool
|
||||
"""
|
||||
wait_time = 0
|
||||
sleep_time = 0.1
|
||||
while True:
|
||||
connections = self.connection_list(uuid=uuid)
|
||||
if not connections:
|
||||
return True
|
||||
wait_time += sleep_time
|
||||
if wait_time > timeout:
|
||||
break
|
||||
|
||||
time.sleep(sleep_time)
|
||||
Util.GMainLoop_iterate_all()
|
||||
def _poll_timeout_cb(unused):
|
||||
if not self.connection_list(uuid=uuid):
|
||||
Util.GMainLoop().quit()
|
||||
|
||||
return False
|
||||
poll_timeout_id = Util.GLib().timeout_add(100, _poll_timeout_cb, None)
|
||||
gone = Util.GMainLoop_run(timeout)
|
||||
Util.GLib().source_remove(poll_timeout_id)
|
||||
return gone
|
||||
|
||||
def connection_activate(self, connection, timeout=15, wait_time=None):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue