Last active
March 10, 2017 01:02
-
-
Save ambv/00641bc0fc101fc91077860649fc6017 to your computer and use it in GitHub Desktop.
Defensive programming for unhandled errors. Add this to preexec_fn= in your subprocess calls.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import sys | |
import signal | |
def ensure_dead_with_parent(): | |
"""A last resort measure to make sure this process dies with its parent. | |
Defensive programming for unhandled errors. | |
""" | |
if not sys.platform.startswith('linux'): | |
return # not supported on OS X, Windows, etc. Use process groups. | |
PR_SET_PDEATHSIG = 1 # include/uapi/linux/prctl.h | |
libc = ctypes.CDLL(ctypes.util.find_library('c')) | |
libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment