python-trio / purerpc

Native, async Python gRPC client and server implementation supporting asyncio, uvloop, and trio
Apache License 2.0
217 stars 15 forks source link

Have support multi process? #25

Closed boylegu closed 4 years ago

boylegu commented 4 years ago

My code:

server = Server(50055, num_processes=5)

server.add_service(JobEngine().service)

server.serve(backend="asyncio")

Exception: TypeError: init() got an unexpected keyword argument 'num_processes'

I don't understand why your example code is shown as if good.

Could you tell me why?

environment: purerpc==0.5.2 python == 3.6

standy66 commented 4 years ago

Hi! With multiprocessing we cannot correctly pass context_manager and setup_fn parameters to Server.add_service if they allocate system resources (connections to databases, for example). On Linux, you can run multiple instances of your server on the same port with SO_REUSEPORT option, this will effectively load balance the traffic on TCP connection level, if this is what you want. I will be updating example code shortly.

boylegu commented 4 years ago

oh~ Thanks a lot!