pythonpython-3.xpyqtrpyc

Update client's GUI widget from Server with RFC widget


I make simple GUI chat program with python

from server call callback function:

def broadcast(self, msg):
    with lock:
        print("bloadcast calls")
        global callbacks
        global buf
        for user, callback in callbacks.items():
            if user not in buf or buf[user] == None:
                buf[user] = (msg,)
            else:
                buf[user] = buf[user] + (msg,)
            callback()

callback function emits client signal

service.root.accept(idt, chat.update.update.emit)

In server's accept function

callbacks[idt] = rpyc.async(callback)

this is it

class Updater(QObject):
    update = pyqtSignal()

In my client class

self.update = Updater()
self.update.update.connect(self.listen)

and listen method is

def listen(self):
    msg = self.service.root.get_buf(self.idt)//get server's message by call server's function
    for m in msg:
        self.log.append(m)

so server call callback function and that make signal in client that update GUI widget

when there is one client, it works well. but when there is more than one client, for example client A and client B, A -message-> server and server update only A's GUI widget. And B's callback blocked until B send message to server. I want that client's GUI update call immediately like interupt call

How can I do that?


Solution

  • just add one line

    rpyc.BgServingThread(service)#service is rpyc connection