How to integrate gRPC to a GLib main loop, or a Qt app, or Twisted python app?

1,635 views
Skip to first unread message

Martin Belanger

unread,
Nov 20, 2015, 5:50:27 PM11/20/15
to grpc.io
Hi,

I'm new to gRPC. I've been reading everything available on the web site (http://www.grpc.io) and running the C++ and Python examples. One thing that is not clear is how to integrate gRPC to processes developed using GLib (https://developer.gnome.org/references), Qt (http://www.qt.io/), or Twisted (https://twistedmatrix.com/trac/).

Over the years I've written several applications (daemons) on Linux platforms. I often used some sort of a framework to design the main loop (e.g. GLib). Libraries like GLib or Twsited provide ways to hook up to the system (signals, interrupts, D-Bus, sysfs, etc...). For example, you may want to hook up a callback when a signal (e.g. SIGTERM) is sent to a daemon. Similarly, GLib, Qt, or Twisted provide ways to hook up to a D-Bus interface so that a daemon can process remote procedure calls over D-Bus. D-Bus, however, is (usually) limited to intra-processor RPC whereas gRPC allows for both intra- and inter-processor RPC.

My question is: Is it possible to add gRPC to a daemon (let's say a GLib-based daemon) and how would one go about doing something like this?

Thanks.


Nathaniel Manista

unread,
Nov 24, 2015, 1:15:49 PM11/24/15
to Martin Belanger, grpc.io
Pleased to meet you, Martin; I'm Nathaniel and I'm leading gRPC Python.

I'm only aware of, and not familiar with, the systems you describe, but I want to answer your question with "yes; what are you seeing that might lead you to think otherwise?". gRPC Python is simply a library that affords functions and objects; while it doesn't have any special hooks in it for cooperating with specific other libraries or frameworks it also doesn't have anything in it that should thwart its behavior in the presence of other code.

Have you tried it out and found yourself hitting a specific problem or are you just asking generally before starting work?
-N

Martin Belanger

unread,
Nov 30, 2015, 5:14:19 PM11/30/15
to grpc.io, mabe...@ciena.com
Hi Nathaniel,

Thanks for taking the time to answer my question.

When I wrote my question I was using past experiences with Twsited, GLib, etc. and I now realize that it does not apply for gRPC. For example, I designed daemons using glib.MainLoop as the main event dispatcher and D-Bus as the RPC protocol to talk to the daemon. I used a library that required to connect the D-Bus dispatcher to GLib's Main Loop. For Python, I used Twisted's reactor as the event dispatcher and again there was an API to connect the D-Bus object to Twisted's reactor. And I assumed something similar was needed for gRPC. But I was wrong.

After I wrote my question to this group, I spent more time looking at gRPC's source code and found that gRPC creates its own threads (pthread) for all its event handling. So no need to connect to a "main loop" dispatcher. gRPC is easier to use than I first thought.

Thanks,
Martin
Reply all
Reply to author
Forward
0 new messages