Hi, I'm trying to run a grpclib server under hypercorn, so far unsuccessfully.
Going off the example in the readme, my server code is basically:
import asyncio
from grpclib.utils import graceful_exit
from grpclib.server import Server
# generated by protoc
from .helloworld_pb2 import HelloReply
from .helloworld_grpc import GreeterBase
class Greeter(GreeterBase):
async def SayHello(self, stream):
request = await stream.recv_message()
message = f'Hello, {request.name}!'
await stream.send_message(HelloReply(message=message))
def create_server():
return Server([Greeter()])
async def main(*, host='127.0.0.1', port=50051):
server = create_server()
# Note: graceful_exit isn't supported in Windows
with graceful_exit([server]):
await server.start(host, port)
print(f'Serving on {host}:{port}')
await server.wait_closed()
I've tried running this using hypercorn server:create_server() as well as hypercorn server:main(), but these both result in errors when I make an actual gRPC call against the server using grpcurl.
For create_server, I get: TypeError: 'Server' object is not callable
For main, I get: TypeError: 'coroutine' object is not callable
Looking at the ASGI spec, it seems like hypercorn expects an ASGI application, e.g., a callable that takes three positional arguments scope, receive, send.
Is there a way to make a grpclib server work with the ASGI spec?
Hi, I'm trying to run a grpclib server under hypercorn, so far unsuccessfully.
Going off the example in the readme, my server code is basically:
I've tried running this using
hypercorn server:create_server()
as well ashypercorn server:main()
, but these both result in errors when I make an actual gRPC call against the server usinggrpcurl
.For
create_server
, I get:TypeError: 'Server' object is not callable
Formain
, I get:TypeError: 'coroutine' object is not callable
Looking at the ASGI spec, it seems like hypercorn expects an ASGI application, e.g., a callable that takes three positional arguments
scope, receive, send
.Is there a way to make a grpclib server work with the ASGI spec?