Fix watchdog reload worker repeatedly if there are multiple changed files
This commit is contained in:
parent
aa6ea5b5a0
commit
59ccf711fa
@ -121,7 +121,7 @@ def kill_process_children(pid):
|
|||||||
pass # should signal error here
|
pass # should signal error here
|
||||||
|
|
||||||
|
|
||||||
def kill_program_completly(proc):
|
def kill_program_completely(proc):
|
||||||
"""Kill worker and it's child processes and exit.
|
"""Kill worker and it's child processes and exit.
|
||||||
|
|
||||||
:param proc: worker process (process ID)
|
:param proc: worker process (process ID)
|
||||||
@ -141,12 +141,14 @@ def watchdog(sleep_interval):
|
|||||||
mtimes = {}
|
mtimes = {}
|
||||||
worker_process = restart_with_reloader()
|
worker_process = restart_with_reloader()
|
||||||
signal.signal(
|
signal.signal(
|
||||||
signal.SIGTERM, lambda *args: kill_program_completly(worker_process)
|
signal.SIGTERM, lambda *args: kill_program_completely(worker_process)
|
||||||
)
|
)
|
||||||
signal.signal(
|
signal.signal(
|
||||||
signal.SIGINT, lambda *args: kill_program_completly(worker_process)
|
signal.SIGINT, lambda *args: kill_program_completely(worker_process)
|
||||||
)
|
)
|
||||||
while True:
|
while True:
|
||||||
|
need_reload = False
|
||||||
|
|
||||||
for filename in _iter_module_files():
|
for filename in _iter_module_files():
|
||||||
try:
|
try:
|
||||||
mtime = os.stat(filename).st_mtime
|
mtime = os.stat(filename).st_mtime
|
||||||
@ -156,12 +158,13 @@ def watchdog(sleep_interval):
|
|||||||
old_time = mtimes.get(filename)
|
old_time = mtimes.get(filename)
|
||||||
if old_time is None:
|
if old_time is None:
|
||||||
mtimes[filename] = mtime
|
mtimes[filename] = mtime
|
||||||
continue
|
|
||||||
elif mtime > old_time:
|
elif mtime > old_time:
|
||||||
kill_process_children(worker_process.pid)
|
|
||||||
worker_process.terminate()
|
|
||||||
worker_process = restart_with_reloader()
|
|
||||||
mtimes[filename] = mtime
|
mtimes[filename] = mtime
|
||||||
break
|
need_reload = True
|
||||||
|
|
||||||
|
if need_reload:
|
||||||
|
kill_process_children(worker_process.pid)
|
||||||
|
worker_process.terminate()
|
||||||
|
worker_process = restart_with_reloader()
|
||||||
|
|
||||||
sleep(sleep_interval)
|
sleep(sleep_interval)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user