title: Reading from sys.stderr in python
body: <p>There are countless amount of questions here about how to read from stderr and stdout of a subprocess. Is it possible to do so with the current process's stderr? I checked it and it raised an IO Error : File not open for reading.</p>
  
  <p>I needed to read the stderr and get the data for further processing. Are there any ways to open the file in 'r+' mode?</p>
  
  <p>One way I thought of was to override the default sys.stderr with a class like:</p>
  
  <pre><code>class CustomStdErr(object):
      def write(self, data):
          with open(fakestderr, 'r+') as f:
              f.write(data)
  
  sys.stderr = CustomStdErr()
  </code></pre>
  
  <p>Are there any other ways to do it more directly?</p>
  
  <p><strong>EDIT:</strong> <em>Why I need the stderr:</em><br>
  There is a thread (call it X) in the code that interacts with the main thread (call it M). The main thread has logging enabled. This is redirected to the stderr. Now, thread X's duty is to monitor stderr and <em>read</em> from it and process that for the main thread. This is, in summary, what's happening.</p>