Monitoring lifetimes with Python bindings
John (J5) Palmieri
johnp at redhat.com
Fri Jul 8 05:56:22 EST 2005
On Thu, 2005-07-07 at 15:35 -0400, Colin Walters wrote:
> On Thu, 2005-07-07 at 15:02 +0200, Ole Laursen wrote:
> > Havoc Pennington <hp at redhat.com> writes:
> > > On Wed, 2005-07-06 at 16:45 -0400, John (J5) Palmieri wrote:
> > >> @dbus.explicitly_pass_message is mainly for debugging. Messages should
> > >> not be exposed in the python bindings. The best thing to do is for your
> > >> client to send its unique name to the server when it connects to the bus
> > >> and register the NameOwnerChanged signal with sender equal to the name
> > >> you received. You can also use the GetNameOwner call to get the unique
> > >> name of an already running process.
> > >
> > > I think exposing messages would be wrong but exposing the caller of a
> > > method may not be if we could figure out a good approach.
> > Perhaps one possibility would be to use another decorator, e.g.
> > @dbus.pass_sender, which would pass a Sender object. Sender could then
> > expose get_name() to return the unique name and a disappeared() hook
> > that you can connect to. The disappeared() hook would then internally
> > register with the NameOwnerChanged signal and also call GetNameOwner
> > to avoid the race condition.
> I think the right approach is probably for the service to create a new
> proxy for the client; the Python binding should have a parallel to the
> GLib bindings' "destroy" signal and watch NameOwnerChanged like the GLib
> bindings do.
This has its ups and downs. The main problem is that you may want to
attach to the destroy signal before the name appears on the bus. Hmm,
perhaps I should change the binding so that you can create a proxy
before the object appears on the bus and get notified when the service
is created. Problem there is I took out the service object but I may
want to add back a Name object. I think you would want to do this per
name and not per object.
Either way, adding API to the bus object makes sense because then you
can do things like register a handler to tell you whenever a name that
starts with a particular namespace, say org.gnome.Service.*, is acquired
on the bus.
John (J5) Palmieri <johnp at redhat.com>
More information about the dbus