title: Windows named pipe: detect in Python on writer side when reader has closed its end without having to write data
body: <p>My application streams (write) data into a named pipe, with the name of the pipe specified as an CLI argument when invoking the application. Streaming data is irregular with phases where there might not be any data to send down the pipe.</p>
  
  <p>I would like to detect when the other process reading from the pipe has closed its end, in order to quickly release the resources my application has allocated for streaming. My issue is now to even detect that the reading end of the pipe has been closed without writing anything into the pipe.</p>
  
  <p>As the stream data format is fixed and allows for no empty writes or pings, I cannot simply try to write some pipe data even if I have nothing to stream in order to see if the pipe reader is still reading.</p>
  
  <p>I have a working solution on Linux, which unfortunately doesn't work on Windows, because Windows named pipes cannot be uniformly handled in select() like on Linux. On Linux, I simply check for the writing end of the pipe to become readable as this signals a pipe error, and then close the pipe and release my allocated resources.</p>
  
  <p>On Windows, this isn't possible. I've opened the pipe for writing as such:</p>
  
  <pre><code>fifo = open('//./pipe/somepipe', 'wb')
  </code></pre>
  
  <p>Trying to <code>fifo.read()</code> from the pipe doesn't work (as is to be expected) and immediately throws an <code>OSException</code>.</p>
  
  <p>As I said, I cannot try some empty/nul write; <code>fifo.write(b'')</code> does nothing, not even poking the pipe for writability at all.</p>
  
  <p>Is there any way on Windows to test the writing end of a named pipe to see if the reader (client) is still connected?</p>