Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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':

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR but seems like we should also fix isinstance(delay, float) to isinstance(10, (int, float)).
What do you think?

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)