From faa4cf629a860d965d75286968f469819e80d5bc Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 31 May 2019 17:05:56 -0700 Subject: [PATCH] webpack: Close potential race condition leaking webpack-dev-server process. This exchanges a race condition where webpack-dev-server might not be stopped on a poorly timed KeyboardInterrupt for a less bad race condition where we might get an UnboundLocalError. Signed-off-by: Anders Kaseorg --- tools/webpack | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/webpack b/tools/webpack index 888ed5ba3e..530e5dd154 100755 --- a/tools/webpack +++ b/tools/webpack @@ -58,18 +58,18 @@ def build_for_dev_server(host, port, minify, disable_host_check): if disable_host_check: webpack_args.append('--disable-host-check') - webpack_process = subprocess.Popen(webpack_args) - - class WebpackConfigFileChangeHandler(pyinotify.ProcessEvent): - def process_default(self, event): - # type: (pyinotify.Event) -> None - nonlocal webpack_process - print('Restarting webpack-dev-server due to config changes...') - webpack_process.terminate() - webpack_process.wait() - webpack_process = subprocess.Popen(webpack_args) - try: + webpack_process = subprocess.Popen(webpack_args) + + class WebpackConfigFileChangeHandler(pyinotify.ProcessEvent): + def process_default(self, event): + # type: (pyinotify.Event) -> None + nonlocal webpack_process + print('Restarting webpack-dev-server due to config changes...') + webpack_process.terminate() + webpack_process.wait() + webpack_process = subprocess.Popen(webpack_args) + watch_manager = pyinotify.WatchManager() event_notifier = pyinotify.Notifier(watch_manager, WebpackConfigFileChangeHandler()) for file in ['webpack.config.ts', 'webpack-helpers.ts', 'webpack.assets.json']: