def invoke_function(func, interaction_model, env): """ Start a gRPC Server to invoke the function :param func: the function :param interaction_model: indicates interaction model: None is single value parameter and return type, 'stream' indicates input and output are generators :param env: a dict containing the runtime environment, usually os.environ :return: None """ grpc_server.run(func, interaction_model, env.get("GRPC_PORT", 10382))
def start_grpc(): # We need to do this because `gunicorn` will spawn a new subprocess ( a worker ) # when running `Flask` server. If we start `gRPC` server before the spawn of # the subprocess, it's nearly impossible to share the `database` with the new # subprocess because Python will copy everything in the memory from the parent # process to the subprocess ( So we have 2 separate instance of `database` ). # The endpoint will start the `gRPC` server in the same subprocess so there is # only one instance of `database`. global grpc_port if grpc_port == 0: port = flask.request.args.get("port", "0") grpc_port = grpc_server.run(port, db) return str(grpc_port) return str(grpc_port)
def invoke_function(func): grpc_server.run(func, os.environ.get("GRPC_PORT", "10382"))