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.
Created on 2012年08月01日 21:56 by Andy.Lutomirski, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg167170 - (view) | Author: Andy Lutomirski (Andy.Lutomirski) | Date: 2012年08月01日 21:56 | |
This program: import subprocess, sys p = subprocess.Popen(['bash', '-c', 'while true; do echo x; sleep 1; done'], bufsize=0, stdout=subprocess.PIPE) for line in p.stdout: sys.stdout.buffer.write(line) sys.stdout.flush() sits around and does nothing on Python 2.7.3. It works (i.e. prints 'x' once per second) on Python 3. This was http://bugs.python.org/issue3907 and is supposedly fixed, but it's not. |
|||
| msg167189 - (view) | Author: Ned Deily (ned.deily) * (Python committer) | Date: 2012年08月02日 05:04 | |
Notice in the reply to Issue3907, "with 2.6, you have to use io.open() explicitly". This is still true in Python 2.7, i.e. the new 3.x-compatible io library is not used by default in Python 2. If you want to use it with subprocess.Popen, one way is to supply a pipe with an io wrapper, perhaps something like: import io, os i, o = os.pipe() piperead = io.open(i,'rb',buffering=0) p = subprocess.Popen(..., stdout=o) See Chapter 15 of the Python 2.7 Standard Library doc for more information on the io module: http://docs.python.org/library/io.html |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:33 | admin | set | github: 59737 |
| 2012年08月02日 05:04:28 | ned.deily | set | status: open -> closed nosy: + ned.deily messages: + msg167189 resolution: works for me stage: resolved |
| 2012年08月01日 22:27:34 | Andy.Lutomirski | set | title: "for line in file" is *still* broken in Python 2.7 -> "for line in file" is *still* broken in Python 2.7 on pipes |
| 2012年08月01日 21:56:37 | Andy.Lutomirski | create | |