def get_gateway(): # type: () -> JavaGateway global _gateway global _lock with _lock: if _gateway is None: # Set the level to WARN to mute the noisy INFO level logs logger.level = WARN # if Java Gateway is already running if 'PYFLINK_GATEWAY_PORT' in os.environ: gateway_port = int(os.environ['PYFLINK_GATEWAY_PORT']) gateway_param = GatewayParameters(port=gateway_port, auto_convert=True) _gateway = JavaGateway( gateway_parameters=gateway_param, callback_server_parameters=CallbackServerParameters( port=0, daemonize=True, daemonize_connections=True)) else: _gateway = launch_gateway() callback_server = _gateway.get_callback_server() callback_server_listening_address = callback_server.get_listening_address() callback_server_listening_port = callback_server.get_listening_port() _gateway.jvm.org.apache.flink.client.python.PythonEnvUtils.resetCallbackClient( _gateway.java_gateway_server, callback_server_listening_address, callback_server_listening_port) # import the flink view import_flink_view(_gateway) install_exception_handler() install_py4j_hooks() _gateway.entry_point.put("PythonFunctionFactory", PythonFunctionFactory()) _gateway.entry_point.put("Watchdog", Watchdog()) return _gateway
def get_gateway(): # type: () -> JavaGateway global _gateway global _lock with _lock: if _gateway is None: # if Java Gateway is already running if 'PYFLINK_GATEWAY_PORT' in os.environ: gateway_port = int(os.environ['PYFLINK_GATEWAY_PORT']) gateway_param = GatewayParameters(port=gateway_port, auto_convert=True) _gateway = JavaGateway(gateway_parameters=gateway_param) else: _gateway = launch_gateway() # import the flink view import_flink_view(_gateway) install_exception_handler() install_py4j_hooks() return _gateway