[Twisted-Python] Using StandardIO and pipes.

Andrew Bennetts andrew at bemusement.org
Thu Aug 9 20:39:08 MDT 2012


Maxim Lacrima wrote:
[…]
> So my conclusions are:
> 1. When I write to stdin of my script from keyboard then
> `self.transport.write()` works as expected.
> 2. When I use pipes or redirection to my script `self.transport.write()`
> doesn't produce any output.
> 3. If I replace self.transport.write() with print statements it works.

Buffering, perhaps?

As a quick test, try adjusting your callback to loseConnection on the transport
after to the write, that should flush the buffers.  If buffering turns out to
be your problem, and you really do expect your pipes to be at most
line-buffered, you'll need to arrange for the buffering on the stdin and stdout
file descriptors to be changed.  I don't think Twisted has that builtin, so you
may need to do that before creating the StandardIO object using the regular
Python APIs.

-Andrew.






More information about the Twisted-Python mailing list