Skip to content

Conversation

Lucas-C
Copy link
Contributor

@Lucas-C Lucas-C commented Mar 27, 2021

Use case

I use the following watch_and_serve.py script:

#!/usr/bin/env python3

from os.path import dirname
from livereload import Server
from other_module import gen_css_bundle

SERVER = Server()
SERVER.watch('index.html')
SERVER.watch('assets/css/main.css', gen_css_bundle)
SERVER.serve(root='.')

The gen_css_bundle function takes a few milliseconds to execute and edit index.html to insert the new bundle filename.

When I run this script and edit main.css, I see the following logs:

[I 210327 10:57:21 watcher:104] Running task: gen_css_bundle (delay: 3)
[I 210327 10:57:21 handlers:95] Reload 1 waiters: ./assets/css/main.css
[I 210327 10:57:22 handlers:82] Ignore: ./index.html

I want to introduce a mechanism in livereload in order to control this "ignore" logic,
so that in my case the brower is reloaded once index.html has been edited by gen_css_bundle.

Suggested solution

Hence, this PR introduces a livereload.handlers.LiveReloadHandler.DEFAULT_RELOAD_TIME class constant,
that can be used this way:

#!/usr/bin/env python3

from os.path import dirname
from livereload import Server
from livereload.handlers import LiveReloadHandler
LiveReloadHandler.DEFAULT_RELOAD_TIME = 0  # do not ignore index.html edition by gen_css_bundle and trigger browser reload
from other_module import gen_css_bundle

SERVER = Server()
SERVER.watch('index.html')
SERVER.watch('assets/css/main.css', gen_css_bundle)
SERVER.serve(root='.')

@Lucas-C Lucas-C force-pushed the configurable-default-reload-time branch from 37ca12c to 8094eb1 Compare December 29, 2022 21:06
@lepture lepture merged commit d042fd3 into lepture:master Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants