Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI flag for using polling based watcher #243

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ Wrap the ``Bottle`` app with livereload server:
# server.watch
server.serve()


pyinotify
---------

If `pyinotify <https://pypi.org/project/pyinotify/>`_ is installed, it will be used for watching file changes instead of the built in polling based watcher. If you prefer to use the built in watcher, specify the ``--poll`` flag on the command line, or initialize the ``Server`` class in a script like in the following

.. code:: python

from livereload import Server
from livereload.watcher import Watcher

server = Server(watcher=Watcher())

The `pyinotify <https://pypi.org/project/pyinotify/>`_ watcher is more efficient than the built in polling based watcher since it does not have to continously poll, but it might fail if the inode of the watched file changes, as might happen when doing a move or a copy or using certain editors such as vi or emacs with backup settings enabled.

Security Report
---------------

Expand Down
11 changes: 10 additions & 1 deletion livereload/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tornado.log

from livereload.server import Server
from livereload.watcher import Watcher


parser = argparse.ArgumentParser(description='Start a `livereload` server')
Expand Down Expand Up @@ -46,6 +47,11 @@
help='Enable Tornado pretty logging',
action='store_true'
)
parser.add_argument(
'-po', '--poll',
help='Use built in polling based watcher instead of pyinotify',
action='store_true'
)


def main(argv=None):
Expand All @@ -55,7 +61,10 @@ def main(argv=None):
tornado.log.enable_pretty_logging()

# Create a new application
server = Server()
if args.poll:
server = Server(watcher=Watcher())
else:
server = Server()
server.watcher.watch(args.target or args.directory, delay=args.wait)
server.serve(host=args.host, port=args.port, root=args.directory,
open_url_delay=args.open_url_delay)