Why does the first loop go wrong with Python3

2015-05-19 Thread Cecil Westerhof
I have the following code: from __future__ import division, print_function import subprocess p = subprocess.Popen('ls -l', shell = True, stdout = subprocess.PIPE) for line in iter(p.stdout.readline, ''): print(line.rstrip().decode('utf-8')) p =

Re: Why does the first loop go wrong with Python3

2015-05-19 Thread Oscar Benjamin
On 19 May 2015 at 13:24, Cecil Westerhof ce...@decebal.nl wrote: I have the following code: from __future__ import division, print_function import subprocess p = subprocess.Popen('ls -l', shell = True, stdout = subprocess.PIPE) for line in iter(p.stdout.readline, ''):

Re: Why does the first loop go wrong with Python3

2015-05-19 Thread Cecil Westerhof
Op Tuesday 19 May 2015 15:16 CEST schreef Oscar Benjamin: On 19 May 2015 at 13:24, Cecil Westerhof ce...@decebal.nl wrote: I have the following code: from __future__ import division, print_function import subprocess p = subprocess.Popen('ls -l', shell = True, stdout = subprocess.PIPE)

Re: Why does the first loop go wrong with Python3

2015-05-19 Thread Thomas Rachel
Am 19.05.2015 um 15:16 schrieb Oscar Benjamin: However the normal way to do this is to iterate over stdout directly: Depends. There may be differences when it comes to buffering etc... Thomas -- https://mail.python.org/mailman/listinfo/python-list

Re: Why does the first loop go wrong with Python3

2015-05-19 Thread Cecil Westerhof
Op Tuesday 19 May 2015 17:49 CEST schreef Ian Kelly: On Tue, May 19, 2015 at 8:44 AM, Cecil Westerhof ce...@decebal.nl wrote: I looked at the documentation. Is it necessary to do a: p.wait() afterwards? It's good practice to clean up zombie processes by waiting on them, but they will also

Re: Why does the first loop go wrong with Python3

2015-05-19 Thread Chris Angelico
On Wed, May 20, 2015 at 2:39 AM, Cecil Westerhof ce...@decebal.nl wrote: By the way, what also works is: p = None But it was just a try in ipython3. I would never do this in real code. I was just curious if this would be handled correctly and it is. :-) That _may_ work, but it depends on

Re: Why does the first loop go wrong with Python3

2015-05-19 Thread Ian Kelly
On Tue, May 19, 2015 at 8:44 AM, Cecil Westerhof ce...@decebal.nl wrote: I looked at the documentation. Is it necessary to do a: p.wait() afterwards? It's good practice to clean up zombie processes by waiting on them, but they will also get cleaned up when your script exits. --