[GDBus] Reopening the session bus

Alberto Mardegan alberto.mardegan at canonical.com
Wed Apr 8 23:57:39 PDT 2015

Hi all!
  I'm writing some tests in python, and I'm setting up a new D-Bus
server for the session bus in each setUp() function, and I'm killing it
at the end of each test case.
The server is started with dbus-launch, whose output is injected into
the environment, so that the code in the test cases can connect to the bus.
This only works for the first test case being executed, because when the
next test case calls g_bus_get(), it gets the same bus used in the
previous test, even though the DBUS_* environment variables have been
changed. I also tried to call close() on the session bus in my cleanUp()
method, and it works, but anyway the next call to g_bus_get() returns
the same old bus (which is now a closed connection).

Is it possible to reopen the connection to the session bus? Or,
alternatively, open a new connection and somehow tell GDBus to return
that connection when someone calls g_bus_get()?

For the time being, I've worked around the issue by not killing the
D-Bus server in between the test cases, but only at the end of the
tests. You can see the code here:


It works, but I would prefer to start each test with a completely clean


More information about the dbus mailing list