Reputation: 1276
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?
Upvotes: 1
Views: 2398
Reputation: 1276
Its a confused question in retrospect. There's no fundamental difference between a session bus or a system bus or any other d-bus. If you want to connect to a bus at a particular address just use dbus.bus.BusConnection:
bus1 = dbus.bus.BusConnection("tcp:host=192.168.0.1,port=1234")
bus2 = dbus.bus.BusConnection("tcp:host=192.168.0.2,port=1234")
Upvotes: 3
Reputation: 30352
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?
Upvotes: 1