Closed pcolladosoto closed 9 months ago
Hello. Can you describe the use case a bit more? Generally killing a program when the pipe it writes to closes is a reasonable default.
Hi! I wrote a small script for parsing the output of vcdcat
to analyse some waveforms. When developing the parser I used head(1)
to get samples of what I would have to process, and that triggered the errors due to head(1)
's intended behaviour. On top of that, if I terminate the parser before it reads the entire output of vcdcat
(say, for only parsing a small subset of the data) the error crops up back again.
Even though this isn't a deal breaker (it just appends some lines at the end of stderr
), I thought it could be worthwhile to have vcdcat
exit cleanly...
Anyway, if you'd like more details I can provide a sample parser.
Thanks a ton for making vcdvcd
!
OK, I'm starting to remember this stuff. A minimal reproduction is:
main.py
#!/usr/bin/env python
# import signal
# signal.signal(signal.SIGPIPE, signal.SIG_DFL)
i = 0
while True:
print(i)
i += 1
then:
main.py | head -n1
blows up with:
Traceback (most recent call last):
File "/home/ciro/test/./main.py", line 6, in <module>
print(i)
BrokenPipeError: [Errno 32] Broken pipe
related:
Let's merge this unless someday we find it causes some problem.
Yep! The example you provided is just what's going on... If anything comes up feel free to let me know so that I can lend a hand if necessary. Thanks a ton for your work again! All the best!
When piping the output of
vcdcat
to programs closing the reading end of the pipe beforevcdcat
finishes writing output theBrokenPipeError
exception is not handled. Givenvcdcat
leverages the builtinprint
function throughout the implementation, we have installed the default handler for theSIGPIPE
signal taking special care to avoid breaking compatibility with Windows (whereSIGPIPE
is not defined).We have also checked the tests mentioned on README.md still pass.
Should another strategy be pursued please feel free to let us know so that we can take a look.
Thanks a ton for developing and extending
vcdvcd
! It's come in quite handy!