I think I'm doing some asynchronous like programming and I'm not sure how to approach this problem. I have a `function X` running on a new thread and a twisted tcp server on the main thread. I want to pass a message to the client when `function X` finishes its job. The code looks something like this:

```
val = None

def x():
    global val
    #do something to val and send message to client that val is ready

class Server(protocol.Protocol):
    def connectionMade(self):
        self.transport.write(b'REDPY*')

    def dataReceived(self, data):
        print("Packet: ",data)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        print("new client")
        return Server()

threading.Thread(target=x).start()

endpoints.serverFromString(reactor, "tcp:1235").listen(EchoFactory())
reactor.run()

```

I've looked into deferred in twisted and event handling, im not really sure what to use.