Skip to content

Commit

Permalink
actually wait for subprocesses in process_killer.kill_me (#774)
Browse files Browse the repository at this point in the history
* actually wait for subprocesses in process_killer.kill_me

* update changelog
  • Loading branch information
pkasprzyk authored Dec 9, 2021
1 parent 873fc8e commit e3200bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## neptune-client 0.13.4

### Fixes
- Fix issue that prevented waiting for subprocesses to finish after receiving stop signal from backend ([#774](https://github.com/neptune-ai/neptune-client/pull/774));
Timeout now overridable using environment var `NEPTUNE_SUBPROCESS_KILL_TIMEOUT`

## neptune-client 0.13.3

### Fixes
Expand Down
2 changes: 2 additions & 0 deletions neptune/new/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@
NEPTUNE_RETRIES_TIMEOUT_ENV = "NEPTUNE_RETRIES_TIMEOUT"

NEPTUNE_SYNC_BATCH_TIMEOUT_ENV = "NEPTUNE_SYNC_BATCH_TIMEOUT"

NEPTUNE_SUBPROCESS_KILL_TIMEOUT = "NEPTUNE_SUBPROCESS_KILL_TIMEOUT"
16 changes: 10 additions & 6 deletions neptune/new/internal/utils/process_killer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import os
import signal

from neptune.new.envs import NEPTUNE_SUBPROCESS_KILL_TIMEOUT

try:
import psutil

Expand All @@ -25,22 +27,24 @@
PSUTIL_INSTALLED = False


KILL_TIMEOUT = 5
KILL_TIMEOUT = int(os.getenv(NEPTUNE_SUBPROCESS_KILL_TIMEOUT, "5"))


def kill_me():
if PSUTIL_INSTALLED:
process = psutil.Process(os.getpid())
try:
children = _get_process_children(process) + [process]
children = _get_process_children(process)
except psutil.NoSuchProcess:
children = []

for process in children:
_terminate(process)
for child_proc in children:
_terminate(child_proc)
_, alive = psutil.wait_procs(children, timeout=KILL_TIMEOUT)
for process in alive:
_kill(process)
for child_proc in alive:
_kill(child_proc)
# finish with terminating self
_terminate(process)
else:
os.kill(os.getpid(), signal.SIGINT)

Expand Down

0 comments on commit e3200bb

Please sign in to comment.