I want to использовал в бридж between в flask webapp and python subprocesses under python3. I couldn't find в copy пас - able example of в service instantiated without config поля for the same.
The reason for wanting to do this is so that I хан have многообразный threads/processes and использовал в single Dbus process схвати в session broker between app instances to hold game state.
Тривиальный All of the Dbus examples I found only included python2.x давайте давать or old versions of whatever mainloop vehicle you prefer.
Этот пример требует:
python3-dbus.mainloop.pyqt5, python3-dbus
пример Сервера:
import signal, sys
signal.signal(signal.SIGINT, signal.SIG_DFL)
from PyQt5.QtCore import *
import math
import dbus
import dbus.service
from dbus.mainloop.pyqt5 import DBusQtMainLoop
class Server(dbus.service.Object):
def __init__(self):
busName = dbus.service.BusName('org.documentroot.Fisticuffs', bus = dbus.SessionBus())
dbus.service.Object.__init__(self, busName, '/Fisticuffs')
#Insert subprocesses here...
@dbus.service.method('org.documentroot.Fisticuffs', in_signature = 's', out_signature = 's')
def move(self, a): return "Move recieved"
@dbus.service.method('org.documentroot.Fisticuffs', in_signature = 'dd', out_signature = 'd')
def add(self, a, b): return a+b
DBusQtMainLoop(set_as_default = True)
app = QCoreApplication(sys.argv)
server = Server()
app.exec_()
Клиентский пример:
import dbus
bus = dbus.SessionBus()
server = bus.get_object('org.documentroot.Fisticuffs', '/Fisticuffs')
print('5 and 10 are:')
print(server.add(5, 10, dbus_interface = 'org.documentroot.Fisticuffs'))
Кредиты:
Адаптированный от здесь , чтобы заставить pyqt5 слушать Ctl + C
и здесь для обновления учебного руководства при том, чтобы заставлять сервер dbus-python работать в PyQt5 mainloop на python3.