title: sys.excepthook is missing, lost sys.stderr
body: <p>I have below snippet of code.</p>
  
  <pre><code>def do_scheme():
      print """
              &lt;scheme&gt;
              &lt;title&gt;ABC&lt;/title&gt;
              &lt;description&gt;ABC is Company&lt;/description&gt;
      """
  if __name__ == "__main__":
     do_scheme()
  </code></pre>
  
  <p>When I executing this CLI with any other commands like: "python test.py | echo $PATH" or "python test.py | cd..", it shows below error message:</p>
  
  <pre><code>close failed in file object destructor:
  sys.excepthook is missing
  lost sys.stderr
  </code></pre>
  
  <p>I have tried to handle sys.excepthook but it didn't work. Is there any decorator we can use here to avoid such error message?</p>