[Twisted-Python] Sending large files over network with perspective broker

Glyph Lefkowitz glyph at twistedmatrix.com
Sun May 23 19:16:34 MDT 2010


On May 23, 2010, at 6:36 PM, Gabriele Lanaro wrote:

> In which sense it's invalid? I don't know how the gtk reactor works, I just guessed that the event loop never reaches the gui events. My idea was to force the processing of these events before spawning another deferred, it's just a workaround, the real problem is  the fact that the server and the client resides in  the same loop (for testing).

It's invalid to run reactor.iterate() inside the reactor mainloop.  You can't force event-processing order in Twisted; if you want an event to not get processed, you need to delay its event source from getting invoked (producer.pauseProducing(), transport.stopReading(), transport.stopWriting(), Deferred.pause() are all ways to do this).

It's invalid to use reactor.iterate() in this way because the reactor may invoke you reentrantly and there's no sane way to handle that.

For example, your code is running because select() said your file descriptor was ready for reading, which then invoked dataReceived, which then invoked your method with buffered data, which then called iterate(), which then called dataReceived, which then called your method with buffered data, which then called iterate(), which then ...
(and so on, forever, unless your application code conflicts with itself and running and starts blowing up and throwing incomprehensible tracebacks everywhere because of "impossible" recursion.

> Which can be the reason of the mainloop "block"?

Lots of reasons.  The example you gave wasn't syntactically valid Python, so it's hard to say.  Consider sending along an <http://sscce.org/> and maybe we can tell you more :).





More information about the Twisted-Python mailing list