I have two microservices:
Tornado service with two endpoints: /foo
and /bar
/foo
async def get(...):
x = await test()
return x
async def test():
y = call to b service, FooBar rpc
return y
/bar
def get(...):
return True
gRPC service with rpc FooBar
rpc FooBar
def FooBar(...):
return requests.get("/bar")
If client hits endpoint /foo
in a service:
/bar
endpoint in a service as that service is blocked.AFAIK, using x=await test() should prevent us of such blocking, what I have missed?
Since the rpc calls aren't async, it will block the Tornado process.
You can avoid blocking the main process by running the rpc calls in a separate thread.
First, make the test()
method regular function, not a coroutine (remove the async
keyword).
Example code:
async def get(...):
x = await IOLoop.current().run_in_executor(None, test)
return x
# regular function, not async
def test(...):
# make calls
return x