def METHOD_NAME(sock, after_idle_sec=1, interval_sec=3, max_fails=5):
    """Set TCP keepalive on an open socket.
    It activates after 5 second (after_idle_sec) of idleness,
    then sends a keepalive ping once every 5 seconds (interval_sec),
    and closes the connection after 5 failed ping (max_fails), or 15 secondes
    re: https://stackoverflow.com/questions/5686490/detect-socket-hangup-without-sending-or-receiving/14780814
    """
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, after_idle_sec)
    sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, interval_sec)
    sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, max_fails)