Create a mailbox object; for the sake of argument, let's say this is a list. It can be a dictionary, or an object, or a file, or a database; whatever you want. Whatever your application.
Then, when you create the ProcessProtocol instance, pass the link to the mailbox. When the relevant data self.mailbox.append(relevantData) , self.mailbox.append(relevantData) .
Also pass a link to this object to your HTTP resource that responds to these requests. Then in render_GET , relevantData = self.mailbox.pop() .
There is no magic way to do this in Twisted. It all depends on many different features of your application and how you want to store and manage this data, which Twisted is clearly not responding to.
The question you really ask really comes down to: “I have an object a (your process protocol) and an object b (your HTTP resource). How do I get a to call a method on b ? This FAQ appears again in different forms in the Twisted community, but it’s very difficult to write a good repeated answer to it, because everyone thinks they are asking another question.
What Twisted does - all that Twisted does, really - displays the occurrence of events outside your process - data coming from subprocesses, networks - into method calls in your process. How you arrange the objects inside, how you keep the links between them, and what you do with the data that Twisted just gave you is completely up to you. This architecture is why Twisted is so powerful. When you learn to snatch the error code from the callback, you will need to leave :).
source share