Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Try process.terminate(), fallback to process.kill() #108

Merged
merged 3 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions nearuplib/nodelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,19 @@ def stop_native(timeout=DEFAULT_WAIT_TIMEOUT):
pid, proc_name, _ = line.strip().split("|")
pid = int(pid)
process = psutil.Process(pid)
logging.info(
f"Near procces is {proc_name} with pid: {pid}...")
logging.info(f"Near procces is {proc_name} with pid: {pid}...")

if proc_name in proc_name_from_pid(pid):
logging.info(
f"Stopping process {proc_name} with pid {pid}...")
process.terminate()
process.wait(timeout=timeout)
logging.info(f"Stopping process {proc_name} with pid {pid}...")
try:
process.terminate()
process.wait(timeout=timeout)
except psutil.TimeoutExpired:
logging.warning(
f"Timeout expired. Killing process {pid}"
)
process.kill()

os.remove(NODE_PID_FILE)
else:
logging.info("Near deamon is not running...")
Expand Down
14 changes: 10 additions & 4 deletions nearuplib/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ def stop_watcher(timeout=DEFAULT_WAIT_TIMEOUT):
with open(WATCHER_PID_FILE) as pid_file:
pid = int(pid_file.read())
process = psutil.Process(pid)
logging.info(
f'Stopping near watcher {process.name()} with pid {pid}...')
process.terminate()
process.wait(timeout=timeout)
logging.info(f'Stopping near watcher {process.name()} with pid {pid}...')

try:
process.terminate()
process.wait(timeout=timeout)
except psutil.TimeoutExpired:
logging.warning('Watcher taking a long time to terminate...')
logging.warning('Killing watcher with pid {pid}')
process.kill()

os.remove(WATCHER_PID_FILE)
else:
logging.info("Nearup watcher is not running...")
Expand Down