async def my_rpc(self, request, context)
...
...
...
stream: AsyncIterable[Response2] = self.runner.get_stream()
        res = list()

        try:
            loop = asyncio.get_running_loop()
            with ProcessPoolExecutor() as executor:
                async for msg in stream:
                    print(msg)
                    if msg.success:
                        stuff = await loop.run_in_executor(executor, 
my_cpu_bound_func, msg.data)
         ....
         ...
        ...
        except Exception as e:
            print(e)


This fails with too_many_pings error and the server side closes the 
connection. But if i take out asyncio.get_running_loop() and consequently 
run_in_executor() and just do the work there like a normal function call, 
it works.
On Friday, September 8, 2023 at 10:54:15 PM UTC-7 Joshua Benz wrote:

> I have python gRPC server that has a handle to a gRPC client for a 
> different python gRPC server. I have an RPC that returns a stream, i use 
> `async for` to iterate over that stream. I was trying to follow this 
> https://docs.python.org/3/library/asyncio-eventloop.html?highlight=run_in_executor#asyncio.loop.run_in_executor
>  
> but I can't get it to work. When I do get_running_loop() and then call 
> loop.run_in_executor with a ProcessPoolExecutor, it always causes 
> "too_many_pings" error. Messing with settings on the client and servers 
> doesn't seem to make a difference.
>
> How do people not block the runtime when doing CPU bound work?
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/88ec6d24-7bc4-49ec-8eb0-520c2ed07c54n%40googlegroups.com.

Reply via email to