Skip to content

Watch server

Watch Server

Used by Mountaineer CLI hooks to isolate your server and push updates to live-reload browsers. You probably won't have to deal with this class explicitly.

mountaineer.watch.PackageWatchdog

PackageWatchdog(
    main_package,
    dependent_packages,
    callbacks=None,
    run_on_bootup=False,
)
PARAMETER DESCRIPTION
run_on_bootup

Typically, we will only notify callback if there has been a change to the filesystem. If this is set to True, we will run all callbacks on bootup as well.

TYPE: bool DEFAULT: False

main_package instance-attribute

main_package = main_package

packages instance-attribute

packages = [main_package] + dependent_packages

paths instance-attribute

paths = []

callbacks instance-attribute

callbacks = callbacks or []

run_on_bootup instance-attribute

run_on_bootup = run_on_bootup

event_handler instance-attribute

event_handler = None

observer instance-attribute

observer = None

start_watching

start_watching()

check_packages_installed

check_packages_installed()

get_package_paths

get_package_paths()

acquire_watchdog_lock

acquire_watchdog_lock()

We only want one watchdog running at a time or otherwise we risk stepping on each other or having infinitely looping file change notifications.

merge_paths

merge_paths(raw_paths)

If one path is a subdirectory of another, we only want to watch the parent directory. This function merges the paths to avoid duplicate watchers.

mountaineer.watch_server.WatcherWebservice

WatcherWebservice(webservice_port=None)

A simple webserver to notify frontends about updated builds.

The WatcherWebservice provides a multiprocessing safe queue that's accessible as notification_queue. Each time that a process wants to update the frontend, it can push a message into the queue.

app instance-attribute

app = build_app()

websockets instance-attribute

websockets = []

port instance-attribute

port = webservice_port or get_free_port()

notification_queue instance-attribute

notification_queue = Queue()

webservice_thread instance-attribute

webservice_thread = None

monitor_build_thread instance-attribute

monitor_build_thread = None

has_started instance-attribute

has_started = False

build_app

build_app()

broadcast_listeners async

broadcast_listeners()

monitor_builds

monitor_builds()

start

start()

stop

stop(wait_for_completion=1)

Attempts to stop the separate WatcherWebservice threads. We will send a termination signal to the threads and wait the desired interval for full completion. If the threads haven't exited after the interval, we will return False. Clients can then decide whether to send a harder termination signal to terminate the threads on the OS level.

mountaineer.cli.IsolatedEnvProcess

IsolatedEnvProcess(build_config, runserver_config=None)

Bases: Process

We need a fully separate process for our runserver and watch, so we're able to re-import all of the dependent files when there are changes.

build_config instance-attribute

build_config = build_config

runserver_config instance-attribute

runserver_config = runserver_config

close_signal instance-attribute

close_signal = Event()

rebuild_channel instance-attribute

rebuild_channel = Queue() if allow_js_reloads else None

rebuild_thread instance-attribute

rebuild_thread = None

run

run()

rebuild_js

rebuild_js()

alert_notification_channel

alert_notification_channel()

Alerts the notification channel of a build update, once the server comes back online. Before this the client might refresh and get a blank page because the server hasn't yet booted.

listen_for_rebuilds

listen_for_rebuilds(app_controller)

If clients place an object into the rebuild channel, our background thread will pick up on these updates and cause a JS-only reload. This only works if the application controller's logic hasn't changed, since we use the global one that was previously created in our isolated process.

run_build

run_build(app_controller)

stop

stop(hard_timeout=5.0)

Client-side stop method to shut down the running process.

handle_dev_exception async

handle_dev_exception(request, exc)