Skip to content

Instantly share code, notes, and snippets.

@iffy
Created November 16, 2011 20:11
Show Gist options
  • Save iffy/1371206 to your computer and use it in GitHub Desktop.
Save iffy/1371206 to your computer and use it in GitHub Desktop.
broken pipe
[matt] /tmp $ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import Popen, PIPE
>>>
>>> f = open('dafile', 'w')
>>> f.write('import sys\n'
... 'raise Exception("hey")')
>>> f.close()
>>>
>>> p = Popen(['python', 'dafile'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
>>> stdout, stderr = p.communicate('foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 691, in communicate
return self._communicate(input)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1222, in _communicate
bytes_written = os.write(self.stdin.fileno(), chunk)
OSError: [Errno 32] Broken pipe
>>>
[matt] /tmp $ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import Popen, PIPE
>>>
>>> f = open('dafile', 'w')
>>> f.write('import sys\n'
... 'raise Exception("hey")')
>>> f.close()
>>>
>>> p = Popen(['python', 'dafile'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
>>> stdout, stderr = p.communicate('foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 691, in communicate
return self._communicate(input)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1222, in _communicate
bytes_written = os.write(self.stdin.fileno(), chunk)
OSError: [Errno 32] Broken pipe
>>>
from subprocess import Popen, PIPE
f = open('dafile', 'w')
f.write('import sys\n'
'raise Exception("hey")')
f.close()
p = Popen(['python', 'dafile'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate('foo')
print 'finished'
$ python f.py
finished
[matt] /tmp $ python f.py
finished
[matt] /tmp $ python f.py
finished
[matt] /tmp $ python f.py
finished
[matt] /tmp $ python f.py
finished
[matt] /tmp $ python f.py
finished
[matt] /tmp $ python f.py
finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment