1

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?

0

2 Answers 2

3

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")
Sign up to request clarification or add additional context in comments.

1 Comment

I was wondering if you know an answer to thus question? stackoverflow.com/questions/71251908/…
1

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?

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.