Skip to content

Commit 47039b7

Browse files
committed
debug termination
1 parent a865ba1 commit 47039b7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

planemo/io.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import fnmatch
66
import os
77
import shutil
8+
import signal
89
import subprocess
910
import sys
1011
import tempfile
@@ -208,10 +209,12 @@ def stop_gravity(virtual_env, gravity_state_dir, env):
208209

209210
def kill_pid_file(pid_file: str):
210211
"""Kill process group corresponding to specified pid file."""
212+
print("Killing process group for pid file: %s" % pid_file)
211213
try:
212214
os.stat(pid_file)
213215
except OSError as e:
214216
if e.errno == errno.ENOENT:
217+
print("Pid file %s does not exist, nothing to kill." % pid_file)
215218
return False
216219

217220
with open(pid_file) as fh:
@@ -228,18 +231,20 @@ def kill_posix(pid: int):
228231

229232
def _check_pid():
230233
try:
231-
os.kill(pid, 0)
234+
os.kill(pid, signal.SIGTERM)
232235
return True
233-
except OSError:
236+
except OSError as e:
237+
print(f"Process {pid} does not exist or is already dead: {e}")
234238
return False
235239

236240
if _check_pid():
237-
for sig in [15, 9]:
241+
for sig in [signal.SIGTERM, signal.SIGKILL]:
238242
try:
239243
# gunicorn (unlike paste), seem to require killing process
240244
# group
241245
os.killpg(os.getpgid(pid), sig)
242-
except OSError:
246+
except OSError as e:
247+
print(f"Failed to kill process group for pid {pid} with signal {sig}: {e}")
243248
return
244249
time.sleep(1)
245250
if not _check_pid():

0 commit comments

Comments
 (0)