'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):

    connection = self._get_connection()
    try:
        connection.shutdown_gateway()
        self.close()
        self.is_connected = False
    except Py4JNetworkError:
        logger.debug(u'Error    while    shutting    down    gateway.', exc_info=True)
        self.shutdown_gateway()
