-1

I would like to have some notification/handler whenever the grpc server opens/closes a new transport connection with some client.

I found this question which leads to this ServerTransportFilter solution. However, this option refers to the grpc-java implementation. I searched for it on the python grpc package and coud not find it.

The closest mechanism I found is the interceptor argument in the server constructor, but this happens every rpc and anyhow does not contain information regarding connection opening/closing.

Lior Cohen
  • 5,570
  • 2
  • 14
  • 30

1 Answers1

1

For client side, Channel.subscribe is what you are looking for.

But for server side, this is a tricky question. The transport logic (TCP socket) is implemented in the gRPC C-Core which is not fully visible to Python wrapper layer. So, currently you can't register handlers for those events.

There might be some way to achieve the functionality in interceptor, but it requires more details about your goal here.

If you think this feature is important for your project, please file an issue to grpc/grpc.

Lidi Zheng
  • 1,801
  • 8
  • 13