summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2021-07-13 07:23:28 -0500
committerDaniil Baturin <daniil@vyos.io>2021-07-13 07:29:52 -0500
commite9c427d9edf215bd348ad58e27d0e6e365dfb7f1 (patch)
treef9936ff878a81a600f9aad1eadd8734c31c218d1 /python/vyos/util.py
parent8e5d635a3c060c00e1828d2ea7a15487cae56468 (diff)
downloadvyos-1x-e9c427d9edf215bd348ad58e27d0e6e365dfb7f1.tar.gz
vyos-1x-e9c427d9edf215bd348ad58e27d0e6e365dfb7f1.zip
T3663: add a small sleep between polling for a new inotify event.
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index d88ca72c0..53e8c08bf 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -518,6 +518,7 @@ def wait_for_inotify(file_path, pre_hook=None, event_type=None, timeout=None, sl
from inotify.adapters import Inotify
from time import time
+ from time import sleep
time_start = time()
@@ -533,11 +534,14 @@ def wait_for_inotify(file_path, pre_hook=None, event_type=None, timeout=None, sl
# the file failed to have been written to and closed within the timeout
raise OSError("Waiting for file {} to be written has failed".format(file_path))
+ # Most such events don't take much time, so it's better to check right away
+ # and sleep later.
if event is not None:
(_, type_names, path, filename) = event
if filename == os.path.basename(file_path):
if event_type in type_names:
return
+ sleep(sleep_interval)
def wait_for_file_write_complete(file_path, pre_hook=None, timeout=None, sleep_interval=0.1):
""" Waits for a process to close a file after opening it in write mode. """