Running multiple services within the same process on Python

1,129 views
Skip to first unread message

dan...@memrise.com

unread,
Jan 13, 2016, 2:42:22 PM1/13/16
to grpc.io
Hi all,

Is it possible to run multiple services (or servicers) on a single process?

It is of course possible to write a single service and add all the methods there. However I have about 50 methods (and would have more in the future) and it'd be nice to separate them into different proto files and implementations. Same way it is done in Java with `addService`. Very much like packages in Java / modules in python.

server = NettyServerBuilder.forPort(port).sslContext(sslContext)
      .addService(GreeterGrpc.bindService(new GreeterImpl())).build()
      .start();

Thanks in advance,
Daniel

Nathaniel Manista

unread,
Jan 13, 2016, 4:05:15 PM1/13/16
to dan...@memrise.com, grpc.io
It's possible but because it's not directly supported by the generated code it's somewhat awkward. Having the generated code support it the use case is something that we intend to do and are tracking in this issue; this comment in the issue lays out the workaround currently required.
-Nathaniel

amber....@nytimes.com

unread,
Jul 25, 2016, 2:47:06 PM7/25/16
to grpc.io, dan...@memrise.com
Now that (as per the linked thread) this has been fixed, is there any documentation about how to do multiple services on one port, post PR-6874?  

Nathaniel Manista

unread,
Jul 26, 2016, 1:15:26 PM7/26/16
to amber....@nytimes.com, grpc.io, Daniel Zohar
On Mon, Jul 25, 2016 at 11:47 AM, <amber....@nytimes.com> wrote:
Now that (as per the linked thread) this has been fixed, is there any documentation about how to do multiple services on one port, post PR-6874?

Does an example count? We've added an example at examples/python/multiplex.
-Nathaniel

Crosson, Amber

unread,
Jul 26, 2016, 1:16:29 PM7/26/16
to Nathaniel Manista, grpc.io, Daniel Zohar
Oh, yes, that's exactly what I was hoping for! Thank you!

Crosson, Amber

unread,
Jul 26, 2016, 1:50:08 PM7/26/16
to Nathaniel Manista, grpc.io, Daniel Zohar
Actually, I'm having an issue running the existing multiplex example out of the box: I'm getting an error that server() takes at least 2 arguments, but only one is given, in line 135 of multiplex_server.py. Do you have any thoughts about that? 

Nathaniel Manista

unread,
Jul 26, 2016, 2:05:05 PM7/26/16
to Crosson, Amber, grpc.io, Daniel Zohar
On Tue, Jul 26, 2016 at 10:50 AM, Crosson, Amber <amber....@nytimes.com> wrote:
Actually, I'm having an issue running the existing multiplex example out of the box: I'm getting an error that server() takes at least 2 arguments, but only one is given, in line 135 of multiplex_server.py. Do you have any thoughts about that?

There's exactly one API change between 0.15 and 1.0.0rc1 and I suspect you're hitting it. Make sure that you have grpcio 1.0.0rc1 installed (you will have to pass "--pre" to pip, as in "pip install --upgrade --pre grpcio==1.0.0rc1").
-Nathaniel

Crosson, Amber

unread,
Jul 26, 2016, 2:06:48 PM7/26/16
to Nathaniel Manista, grpc.io, Daniel Zohar
That was it. Thank you very much!
Reply all
Reply to author
Forward
0 new messages