Fix auto_reload in Linux (#1286)

* Fix two problems with the auto_reloader in Linux.
1) Change 'posix' to 'linux' in sys.plaform check, because 'posix' is an invalid value and 'linux' is the correct value to use here.
2) In kill_process_children, don't just kill the 2nd level procs, also kill the 1st level procs.
   Also in kill_process_children, catch and ignore errors in the case that the child proc is already killed.

* Fix flake8 formatting on PR
This commit is contained in:
Ashley Sommer 2018-08-17 16:30:03 +10:00 committed by Raphael Deem
parent 1814ff05f4
commit 79e35bbdf6

View File

@ -74,7 +74,14 @@ def kill_process_children_unix(pid):
with open(children_proc_path) as children_list_file_2: with open(children_proc_path) as children_list_file_2:
children_list_pid_2 = children_list_file_2.read().split() children_list_pid_2 = children_list_file_2.read().split()
for _pid in children_list_pid_2: for _pid in children_list_pid_2:
try:
os.kill(int(_pid), signal.SIGTERM) os.kill(int(_pid), signal.SIGTERM)
except ProcessLookupError:
continue
try:
os.kill(int(child_pid), signal.SIGTERM)
except ProcessLookupError:
continue
def kill_process_children_osx(pid): def kill_process_children_osx(pid):
@ -94,7 +101,7 @@ def kill_process_children(pid):
""" """
if sys.platform == 'darwin': if sys.platform == 'darwin':
kill_process_children_osx(pid) kill_process_children_osx(pid)
elif sys.platform == 'posix': elif sys.platform == 'linux':
kill_process_children_unix(pid) kill_process_children_unix(pid)
else: else:
pass # should signal error here pass # should signal error here
@ -136,8 +143,8 @@ def watchdog(sleep_interval):
continue continue
elif mtime > old_time: elif mtime > old_time:
kill_process_children(worker_process.pid) kill_process_children(worker_process.pid)
worker_process.terminate()
worker_process = restart_with_reloader() worker_process = restart_with_reloader()
mtimes[filename] = mtime mtimes[filename] = mtime
break break