问题
I searched for an answer to this question in several places, but I could not find a consistent solution, and some are too old and unclear.
I have a classe where the interface path for dbus is generated in runtime, so I need to export methods with the properly interface, for example:
One instance of my service start dbus with interface br.example.MyInterface.Number1
, and a second instance of service start dbus with br.example.MyInterface.Number2
, so the decorator for each method will be:
br.example.MyInterface.Number1
; and
br.example.MyInterface.Number2
Cannot make this work with static decorator like @dbus.service.method('com.example.MyInterface.Number1')
, because they are distincts.
How can I export methods to dbus in runtime using python?
回答1:
@dbus.service.method('com.example.MyInterface.Number%d' % (instancenum,))
来源:https://stackoverflow.com/questions/13810613/how-dynamically-export-methods-to-dbus-using-python-without-static-decorator