'Sends a shutdown command to the gateway. This will close the gateway
server: all active connections will be closed. This may be useful
if the lifecycle of the Java program must be tied to the Python
program.'

def shutdown_gateway(self):

    if (not self.is_connected):
        raise Py4JError(u'Gateway    must    be    connected    to    send    shutdown    cmd.')
    try:
        quiet_close(self.stream)
        self.socket.sendall(proto.SHUTDOWN_GATEWAY_COMMAND_NAME.encode(u'utf-8'))
        quiet_close(self.socket)
        self.is_connected = False
    except Exception:
        logger.debug(u'Exception    occurred    while    shutting    down    gateway', exc_info=True)
