This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amoffat
Recipients amoffat
Date 2012-02-13.09:54:08
SpamBayes Score 9.127795e-07
Marked as misclassified No
Message-id <1329126849.72.0.845817080547.issue14000@psf.upfronthosting.co.za>
In-reply-to
Content
The following code only works if the "p.stdin.close()" line is uncommented.  It seems that stdin only flushes to the process on stdin.close(), not on stdin.flush().

-----------------------------------

import subprocess as subp
import threading
import time


p = subp.Popen(["tr", "[:lower:]", "[:upper:]"],
    stdin=subp.PIPE, stderr=subp.PIPE, stdout=subp.PIPE, close_fds=True)


def read(stdout):
    while True:
        line = stdout.readline()
        if not line: break
        print(line.decode("utf8"))

t = threading.Thread(target=read, args=(p.stdout,))
t.daemon = True
t.start()

p.stdin.write("uppercase\n".encode())
p.stdin.flush()
#p.stdin.close()

time.sleep(1)
History
Date User Action Args
2012-02-13 09:54:09amoffatsetrecipients: + amoffat
2012-02-13 09:54:09amoffatsetmessageid: <1329126849.72.0.845817080547.issue14000@psf.upfronthosting.co.za>
2012-02-13 09:54:09amoffatlinkissue14000 messages
2012-02-13 09:54:08amoffatcreate