What are the IPC mechanisms provided that work well with Gtk and Python?

Hi, this is Chapter II of Art of Making Plugins (Please read that, if you want, its not necessary though). I want to implement IPC in my Gtk application written in Python. What are the best IPC mechanism available? It will be great and excellent if that IPC mechanism is a GNOME project, like something provided by Gio module.

I read about GDBUS, and I like it, but it doesn’t support Windows (from the DBUS website, or does it?), so I looking for similar to that. One constraint is that it should be able to transport basic data like string, number and variable-length list. Please help me with this. :smile:

DBus works fine on Windows and macOS; on those platforms you don’t have access to a shared system and session buses, but you can use DBus for IPC within your application.

2 Likes

Can you please give me a demo example written in Python or point to any tutorial?

Python has at least three separate DBus modules:

  • dbus-python, which wraps the reference libdbus implementation library, and has some syntactic sugar for Python types; it’s not really maintained, and has a series of well-known design problems
  • dbussy, a binding that uses asyncio, but does not really integrate with GLib’s main loop, so it’s more geared towards pure Python projects
  • GDBus, which is part of Gio and as such it’s heavily integrated within the GLib/GTK/GNOME core platform; the PyGObject bindings have some glue code that makes it slightly more Pythonic, but you may end up using GLib.Variant and other low level API if you get out of the beaten path; additionally, if you’re defining your own interfaces, you’ll have to generate your own code to create proxies and skeleton objects

I don’t have Python examples to give you, I’m afraid.

1 Like

Thank you, whatever happens I will stick with GDBus. So I need to learn about GLib.Variants, it’s going to be interesting! Thanks again :slight_smile:

Another approach would be the use of pipes

https://developer.gnome.org/glib/stable/glib-UNIX-specific-utilities-and-integration.html

or you could make use of a socket

https://developer.gnome.org/gio/stable/GSocket.html

In gsequencer we have a dependency on Libsoup2.4 and doing OSC messages, this gives us a network capable IPC, which can even being routed.

https://developer.gnome.org/libsoup/stable/
nongnu.org/gsequencer/api/libags/AgsServer.html
http://nongnu.org/gsequencer/api/libags-audio/AgsOscServer.html

Note, you can call Gtk3 code only within its very own GMainLoop.

1 Like

Pipes approach seems limited to UNIX platforms, so I’m not going with it. Let me have a look at sockets approach, yeah, things are getting more abstract. [Hope I don’t end up in Assembly language :joy: ]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.