<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.8.5">
</HEAD>
<BODY>
On Thu, 2015-04-09 at 09:57 +0300, Alberto Mardegan wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
  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).
</PRE>
</BLOCKQUOTE>
<BR>
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).<BR>
<BR>
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.<BR>
<BR>
https://bazaar.launchpad.net/~indicator-applet-developers/indicator-sound/trunk.15.04/view/head:/tests/notifications-test.cc#L84<BR>
<BR>
Ted
</BODY>
</HTML>