
On 02:27 am, rutt.4@osu.edu wrote:
Dear twisted-python,
I 19m trying to integrate a python REPL into my existing twisted 8.2.0 client-side program (which talks to another twisted server running a custom protocol). This client side program uses twisted.internet.stdio.StandardIO already to interact with the user, to read commands from the user and send them to the server. What 19s the best way to add functionality to drop into a python REPL? I adapted the doc/core/examples/stdin.py code below to drop into the 18code 19 stdlib module to try to model for the mailing list what my larger client program is trying to do. It works fine on linux, until you enter a command which outputs a large amount of data, at which point you get a 1CResource temporarily unavailable 1D as can be seen below. I 19m assuming the issue is related to StandardIO taking control of reads/writes to the stdio file descriptors, and not integrating well with python code that writes directly to sys.stderr, but I 19m not sure what the right solution is.
In addition to what Andrew said, I'll also point out that rather than making code that expects blocking writes to stdout work by putting stdout back into blocking mode, you can make it work by instead providing a stdout which will buffer anything that cannot immediately be written non-blockingly. StandardIO gives you exactly this; its `write` knows how to deal with non-blocking descriptors and buffer as necessary. This is why manhole doesn't have the same problem as your code calling directly into `code.interact`. For details, <http://twistedmatrix.com/trac/browser/trunk/twisted/conch/manhole.py#L45>. Jean-Paul