Skip to content

Commit

Permalink
run-dev: Wait for children to exit on Ctrl+C instead of killing them.
Browse files Browse the repository at this point in the history
In addition to being generally less unfriendly, this works around a
bug in Node.js that causes webpack-dev-server to corrupt the terminal
state when exiting as a background process.

nodejs/node#35536

Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk committed Oct 7, 2020
1 parent efd9b19 commit 6ba802b
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tools/run-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import signal
import subprocess
import sys
import traceback
from typing import Any, Callable, Generator, List, Sequence
from urllib.parse import urlunparse

Expand Down Expand Up @@ -364,15 +363,15 @@ def print_listeners() -> None:

children = []

if options.test:
do_one_time_webpack_compile()
else:
children.append(start_webpack_watcher())
try:
if options.test:
do_one_time_webpack_compile()
else:
children.append(start_webpack_watcher())

for cmd in server_processes():
children.append(subprocess.Popen(cmd))
for cmd in server_processes():
children.append(subprocess.Popen(cmd))

try:
app = Application(enable_logging=options.enable_tornado_logging)
try:
app.listen(proxy_port, address=options.interface)
Expand All @@ -387,13 +386,8 @@ def print_listeners() -> None:
for s in (signal.SIGINT, signal.SIGTERM):
signal.signal(s, shutdown_handler)
ioloop.start()
except Exception:
# Print the traceback before we get SIGTERM and die.
traceback.print_exc()
raise
finally:
# Kill everything in our process group.
#os.killpg(0, signal.SIGTERM)
print("Waiting for children to stop...")
for child in children:
child.wait()

Expand Down

0 comments on commit 6ba802b

Please sign in to comment.