- edited description
Python3 byte conversion and flushing
Python 3.7.0, Sarge 0.1.5.post0 (through pip).
I followed the tutorial part "Interacting with child processes".
With Python 3, I had to execute the example slightly differently to get it to work. Please consider changing the docs, or telling me if I did something wrong :)
1) >>> p.stdin.write('Fred\n')
has to be passed a bytes object (p.stdin.write(b'Fred\n')
) (otherwise: TypeError: a bytes-like object is required, not 'str').
2) >>> p.stdin.write('Fred\n')
>>> p.stdout.readline()
requires p.stdin.flush()
to be called after writing to stdin, otherwise stdout will be empty.
There seems to be some kind of bug in Popen
(see: https://stackoverflow.com/questions/27571305/subprocess-stdin-buffer-not-flushing-on-newline-with-bufsize-1), but even adding the suggested universal_newlines=True
to the Command
object didn't work for me (stdout empty, only works when flushing stdin).
Comments (3)
-
reporter -
repo owner - changed status to resolved
Thanks for the report. I've updated the documentation, see
https://sarge.readthedocs.io/en/latest/tutorial.html#interacting-with-child-processes
(you may need to clear your browser cache to get the latest version of the documentation page).
-
reporter Thanks!
- Log in to comment