Nonblocking fifo
<p>How can I make a fifo between two python processes, that allow dropping of lines if the reader is not able to handle the input?</p>

<ul>
<li>If the reader tries to <code>read</code> or <code>readline</code> faster then the writer writes, it should block.</li>
<li>If the reader cannot work as fast as the writer writes, the writer should not block. Lines should not be buffered (except one line at a time) and only the last line written should be received by the reader on its next <code>readline</code> attempt.</li>
</ul>

<p>Is this possible with a named fifo, or is there any other simple way for achiving this?</p>

<p>Well, that's not actually a FIFO (queue) as far as I am aware - it's a single variable. I suppose it might be implementable if you set up a queue or pipe with a maximum size of 1, but it seems that it would work better to use a <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Lock" rel="nofollow"><code>Lock</code></a> on a single object in one of the processes, which the other process references via a <a href="https://docs.python.org/3/library/multiprocessing.html#proxy-objects" rel="nofollow">proxy object</a>. The reader would set it to <code>None</code> whenever it reads, and the writer would overwrite the contents every time it writes.</p>

<p>You can get those to the other processes by passing the proxy of the object, and a proxy of the lock, as an argument to all relevant processes. To get it slightly more conveniently, you can use a <a href="https://docs.python.org/3/library/multiprocessing.html#managers" rel="nofollow"><code>Manager</code></a>, which provides a single object with proxy that you can pass in, which contains and provides proxies for whatever other objects (including locks) you want to put in it. <a href="http://stackoverflow.com/a/9436866/6051861">This answer</a> provides a useful example of proper use of a Manager to pass objects into a new process.</p>

python blocking nonblocking fifo