Py2exe error handling redirection and popup

I tried to figure out how to get py2exe to handle errors more elegantly. Two strange things basically happen:

1) A pop-up message after turning off the program => you need to disable (do not show) this pop-up window

2) Creating a log file created in c: \ Program Files \ AppName \ AppName.exe.log (sometimes with write permissions to this folder) => redirect the log to c: \ ProgramData p>

I think I can just put the code in the wrong place, and the py2exe bootstrap code runs AFTER I installed them, but I'm not sure. I tried putting this code right before I generated the error log, but it still goes where py2exe loads them (StdErr objects)


The structure of my program is as follows

src/ python/ gui/ __main__.py 

Basic .py

 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() 
+6
source share
2 answers

This is an old post, but still someone may find it convenient. You can turn off this annoying popup by specifying the distribution of loggers

 logger.propagate = False 

The reason is that the log does not distribute the output to the console. For more information, check the source code in the py2exe package:

 py2exe\boot_common.py 
+4
source

I had problems when one of import made a mistake right at the top of my file. I had to transfer the stdout / stderr redirect directly to the top of the file to ensure that the logs were not created as py2exe would like.

+1
source

Source: https://habr.com/ru/post/953943/


All Articles