title: py2exe error handling redirection and popup
body: <p>Been trying to figure out how to get py2exe to handle errors more gracefully.  There are basically 2 weird things happening:</p>
  
  <p>1) Popup message after shutting down the program => want to suppress (not show up) this popup </p>
  
  <ul>
  <li>Use try/except => doesn't work
  <ul>
  <li><a href="http://osdir.com/ml/python.py2exe/2006-09/msg00016.html">http://osdir.com/ml/python.py2exe/2006-09/msg00016.html</a></li>
  <li>Not sure where to put this code</li>
  </ul></li>
  </ul>
  
  <p>2) Log file getting created in c:\Program Files\AppName\AppName.exe.log (sometimes has permission errors writing to this folder) => redirect log to c:\ProgramData</p>
  
  <ul>
  <li>Use sys.stdout and sys.stderr => doesn't work
  <ul>
  <li><a href="http://www.dreamincode.net/forums/topic/234318-py2exe-do-not-show-errors-occurred-prompt-to-user/">http://www.dreamincode.net/forums/topic/234318-py2exe-do-not-show-errors-occurred-prompt-to-user/</a></li>
  <li>Not sure where to put this code</li>
  </ul></li>
  </ul>
  
  <p>I'm thinking that I may just be putting the code in the wrong spot and the py2exe bootstrap code is firing AFTER I've set these up but I'm not sure.  I've tried putting this code right before the error log is generate but it still goes to where py2exe is bootstrapping them to (the StdErr objects)</p>
  
  <hr>
  
  <p>The structure of my program is as follows</p>
  
  <pre><code>src/
    python/
      gui/
        __main__.py
  </code></pre>
  
  <p><strong>main</strong>.py</p>
  
  <pre><code>if __name__ == "__main__":
      # Redirect py2exe log to somewhere else if windows
      if hasattr(sys,"frozen") and sys.frozen in ("windows_exe", "console_exe"):
          stdout_file = "c:\ProgramData\AppName\out.log"
          stderr_file = "c:\ProgramData\AppName\err.log"
          sys.stdout = open(stdout_file, "w")
          sys.stderr = open(stderr_file, "w")
      try:
          gui = AppNameGui()
          gui.main()
      except:
          traceback.print_exc()
  </code></pre>