<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Die Welt ist gar nicht so. &#187; shell</title>
	<atom:link href="http://blog.dieweltistgarnichtso.net/tag/shell/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.dieweltistgarnichtso.net</link>
	<description>Sie ist ganz anders.</description>
	<lastBuildDate>Mon, 23 Sep 2013 15:41:20 +0000</lastBuildDate>
	<language>de-DE</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.35</generator>
	<item>
		<title>Fixing IPython Pipe Handling</title>
		<link>http://blog.dieweltistgarnichtso.net/fixing-ipython-pipe-handling</link>
		<comments>http://blog.dieweltistgarnichtso.net/fixing-ipython-pipe-handling#comments</comments>
		<pubDate>Mon, 10 Oct 2011 13:27:54 +0000</pubDate>
		<dc:creator><![CDATA[erlehmann]]></dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[ipython]]></category>
		<category><![CDATA[pipe]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sigpipe]]></category>

		<guid isPermaLink="false">http://blog.dieweltistgarnichtso.net/?p=3907</guid>
		<description><![CDATA[On my Laptop, I use IPython as the default shell. Lately, I noticed pipe handling to be broken in some specific cases. I could trace this back to Python ignoring the SIGPIPE signal. SIGPIPE gets sent to a process when &#8230; <a href="http://blog.dieweltistgarnichtso.net/fixing-ipython-pipe-handling">Weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>
On my Laptop, I use <a href="http://ipython.org/ipython-doc/dev/interactive/shell.html"><i>IPython</i> as the default shell</a>. Lately, I noticed <a href="http://en.wikipedia.org/wiki/Pipeline_%28Unix%29"><i>pipe</i> handling</a> to be broken in some specific cases. I could trace this back to Python ignoring the <a href="http://en.wikipedia.org/wiki/SIGPIPE"><i>SIGPIPE</i></a> signal.
</p>
<p>
<i>SIGPIPE</i> gets sent to a process when it tries to write to a pipe that is not read by another process. The default action for a process under these circumstances is to terminate.
</p>
<p>
Imagine a process yielding a huge amount of text, piped to <a href="https://www.gnu.org/software/coreutils/manual/html_node/head-invocation.html"><i>head</i></a> to print the first ten lines. With <i>SIGPIPE</i> ignored, the process will continue after head has stopped reading. Usually, this will only affect runtime – however, if the original process outputs an endless data stream, the shell will hang.
</p>
<p>
To check whether your shell ignores <i>SIGPIPE</i>, try the following command: <kbd>yes | tee | head</kbd>. It should print 10 lines with a single <samp>y</samp> each, then terminate. If the shell hangs, printing a message similar to <samp>tee: standard output: Broken pipe</samp>, <i>SIGPIPE</i> is ignored.
</p>
<p>
<b><abbr title="Too long; didn't read">TL;DR</abbr>:</b> In <i>IPython</i>, proper <i>SIGPIPE</i> handling can be restored using the <a href="http://docs.python.org/library/signal.html"><i>signal</i> module</a>: <code>signal.signal(signal.SIGPIPE, signal.SIG_DFL)</code>.
</p>
<h3>Further reading</h3>
<ul>
<li><a href="http://bugs.python.org/issue1652">Python tracker: <i>Issue 1652: subprocess should have an option to restore SIGPIPE to default action</i></a></li>
<li><a href="http://www.chiark.greenend.org.uk/ucgi/~cjwatson/blosxom/2009-07-02-python-sigpipe.html"><i>Python SIGPIPE Handling</i></a></li>
<li><a href="http://blog.nelhage.com/2010/02/a-very-subtle-bug/"><i>A Very Subtle Bug</i></a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://blog.dieweltistgarnichtso.net/fixing-ipython-pipe-handling/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
