1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
from pydbus import SessionBus, connect
import os
DBUS_SESSION_BUS_ADDRESS = os.getenv("DBUS_SESSION_BUS_ADDRESS")
with connect(DBUS_SESSION_BUS_ADDRESS) as bus:
bus.dbus
del bus._dbus
try:
bus.dbus
assert(False)
except RuntimeError:
pass
with SessionBus() as bus:
pass
# SessionBus() and SystemBus() are not closed automatically, so this should work:
bus.dbus
with bus.request_name("net.lew21.Test"):
pass
with bus.request_name("net.lew21.Test"):
pass
with bus.request_name("net.lew21.Test"):
try:
bus.request_name("net.lew21.Test")
assert(False)
except RuntimeError:
pass
with bus.watch_name("net.lew21.Test"):
pass
with bus.subscribe(sender="net.lew21.Test"):
pass
|