[GDBus] Reopening the session bus

Ted Gould ted at gould.cx
Thu Apr 9 06:19:54 PDT 2015


On Thu, 2015-04-09 at 09:57 +0300, Alberto Mardegan wrote:

>   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).


The issue seems to be related to the multi-threaded nature of GDBus,
basically the thread has to shutdown, which it starts when you unref the
instance, but it might not complete before the next test runs. Then it
goes "hey, already running, cool!" which is not what you actually want
in this situation (but great in real programs).

To work around this we've been putting a weak reference unto the session
bus, dropping our reference, and then waiting for the weak pointer to
clear the memory location. Not sure how you'd implement that in Python
though.

https://bazaar.launchpad.net/~indicator-applet-developers/indicator-sound/trunk.15.04/view/head:/tests/notifications-test.cc#L84

Ted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20150409/51d1c4ce/attachment-0001.html>


More information about the dbus mailing list