tags:

views:

43

answers:

1

hi!

I've written a script that connects to d-bus session bus on a remote computer like so:

os.environ["DBUS_SESSION_BUS_ADDRESS"] = "tcp:host=192.168.0.1,port=1234"
bus = dbus.SessionBus()

That works fine except now I need to be able to connect to multiple session buses on different computers. I've tried the following:

os.environ["DBUS_SESSION_BUS_ADDRESS"] = "tcp:host=192.168.0.1,port=1234"
bus1 = dbus.SessionBus()
os.environ["DBUS_SESSION_BUS_ADDRESS"] = "tcp:host=192.168.0.2,port=1234"
bus2 = dbus.SessionBus()

But it doesn't work. The second call to SessionBus returns the same object as the first call. ie. in this case both objects refer to the session bus on 192.168.0.1. It seems only the first call to SessionBus actually does anything and all subsequent calls just return the object that was created on the first call. Does anyone know a way around this?

A: 

Poking around in the Python/DBUS source, I notice that in _dbus.py, SessionBus.__new__ takes a private boolean parameter:

`private` : bool
    If true, never return an existing shared instance, but instead
    return a private connection.

Does bus = dbus.SessionBus(private=True) make a difference?

detly
Thanks. It'll be a few days until I get a chance to test it now, but that sounds promising.
Shum
Didn't work unfortunately. Both bus objects still talk to the same IP address.
Shum