Sorry to reply to myself again, but I think I now know the answer and wish to post it for the archives.
Python run without '-i', if not sys.stdin.isatty(), expects to read a whole script before doing anything else (presuming to be reading it from a pipe). Therefore syntax errors are fatal, but otherwise nothing is executed until EOF. So the answer to my question is to run: $ ssh localhost python -ui Best wishes, Hamish On Feb 13, 2008 4:20 PM, Hamish Allan <[EMAIL PROTECTED]> wrote: > Further to my query about trying to make Python run unbuffered, I have > discovered that a SyntaxError seems to cause Python to close its SSH > connection: > > $ ssh localhost python -u > , > File "<stdin>", line 1 > , > ^ > SyntaxError: invalid syntax > $ > > Whereas a different sort of error (e.g. NameError) does not: > > $ ssh localhost python -u > pront > [^D] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > NameError: name 'pront' is not defined > $ > > Can anyone tell me why?! > > Thanks, > Hamish > > > On Feb 13, 2008 1:12 AM, Hamish Allan <[EMAIL PROTECTED]> wrote: > > Hi, > > > > The man page for python says: > > > > "-u Force stdin, stdout and stderr to be totally unbuffered." > > > > However, when I try: > > > > $ ssh localhost python -u > > print 'hello, world' > > [^D] > > hello, world > > $ > > > > Nothing happens until I send that EOF. I'm pretty sure it's not SSH > > that's buffering because when I try: > > > > $ ssh localhost bash > > echo 'hello, world' > > hello, world > > [^D] > > $ > > > > The 'hello, world' comes back immediately (I don't need to send the EOF). > > > > I've also tried: > > > > $ ssh localhost python -u > > import sys > > sys.stdout.write('hello, world\n') > > sys.stdout.flush() > > [^D] > > hello, world > > $ > > > > Again, nothing happens until I send the EOF. How can I get Python to > > run over SSH unbuffered? > > > > Thanks, > > Hamish > > > -- http://mail.python.org/mailman/listinfo/python-list