pythonpython-3.xthread-safetytwistedtwisted.internet

Twisted Tkinter Manual Data Input Not Working


I'm working on an application for use in a reception/office environment that allows for the sending of notices to specific offices/computers or in my case for testing at the moment globally to all connected clients. The issue I have faced is that the server claims to send and write to the transport the notification but the client never receives it, all the initial connection data is processed and printed but nothing further unless apart of the main reconnection functions and other methods built-in to the twisted override methods.

Is there perhaps something in the server end that is trying to write to transport but just isn't actually being done? I've split the code in a few files which are all over here: https://github.com/FlopsiBunny/ReceptionDemo but the main culprit is:

# ReceptionDemo/Console/lib/offices.py
def submit(self, *args):

        # Submit Notification to Server
        title = self.titleEntry.get("1.0", END)
        message = self.messageEntry.get("1.0", END)

        # Notification Setup
        notif = Notification(title, message)

        # Send Notification
        if self.office == None:
            reactor.callFromThread(self.parent.factory.send_global_notice, notif)

        # Destroy Window
        self.destroy()
# ReceptionDemo/Console/lib/server.py (Function inside the Client Protocol class)
def sendNotice(self, notification):

        # Send Notification
        token = self.token
        notification.update_token(token)

        notifData = jsonpickle.encode(notification)
                        
        response = {
           "token": token,
           "payload": notifData
        }
        responseData = jsonpickle.encode(response)
        print("Sending...")
        reactor.callFromThread(self.transport.write, responseData.encode("utf-8"))
        self.transport.write(str("Tada").encode("utf-8"))
        self.console.log("Sending Notice to " + str(self._peer.host + ":" + str(self._peer.port)))
        print(responseData)
        print("Sent")

If anyone could provide a solution that would be great, I have a feeling it's a threading issue but I am not the most adept at threading.


Solution

  • Found the problem, bug with Tksupport of Twisted and child windows of the root window, one example is dialogs will freeze the Twisted reactor whereas a Toplevel window will deadlock the reactor.