Skip to content

Commit

Permalink
Fix handling of 'forever' delay (fixes lepture#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnix committed Sep 14, 2021
1 parent 8f114c4 commit 5bab70d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions livereload/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def examine(self):
if changed:
func = item['func']
delay = item['delay']
if delay and isinstance(delay, float):
if delay and isinstance(delay, float) or delay == 'forever':
delays.add(delay)
if func:
name = getattr(func, 'name', None)
Expand All @@ -108,8 +108,10 @@ def examine(self):
else:
func()

if delays:
delay = max(delays)
if delays == {'forever'}:
delay = 'forever'
elif delays:
delay = max(delays - {'forever'})
else:
delay = None
return self.filepath, delay
Expand Down
15 changes: 15 additions & 0 deletions tests/test_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,18 @@ def test_watch_multiple_dirs(self):
os.remove(second_path)
assert watcher.examine() == (second_path, None)
assert watcher.examine() == (None, None)

def test_watch_delay_forever(self):
watcher = Watcher()

filepath = os.path.join(tmpdir, 'foo')
abs_filepath = os.path.abspath(filepath)

with open(filepath, 'w') as f:
f.write('')

watcher.watch(filepath, delay=1.0)
watcher.watch(filepath, delay='forever')

assert watcher.examine() == (abs_filepath, 'forever')
assert watcher.examine() == (None, None)

0 comments on commit 5bab70d

Please sign in to comment.