py2exe error handling redirection and popup

2024/4/15 1:54:25

Been trying to figure out how to get py2exe to handle errors more gracefully. There are basically 2 weird things happening:

1) Popup message after shutting down the program => want to suppress (not show up) this popup

  • Use try/except => doesn't work
    • http://osdir.com/ml/python.py2exe/2006-09/msg00016.html
    • Not sure where to put this code

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

  • Use sys.stdout and sys.stderr => doesn't work
    • http://www.dreamincode.net/forums/topic/234318-py2exe-do-not-show-errors-occurred-prompt-to-user/
    • Not sure where to put this code

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)


The structure of my program is as follows

src/python/gui/__main__.py

main.py

if __name__ == "__main__":# Redirect py2exe log to somewhere else if windowsif 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()
Answer

It is old post but still, someone could find it handy. You can disable this annoying popup window by set logger propagation

logger.propagate = False

The reason is that logger is not propagate output to console. For more details check source code in py2exe package:

py2exe\boot_common.py
https://en.xdnf.cn/q/73229.html

Related Q&A

SQL statement for CSV files on IPython notebook

I have a tabledata.csv file and I have been using pandas.read_csv to read or choose specific columns with specific conditions.For instance I use the following code to select all "name" where …

How to draw ellipsoid with plotly

Are there any way to plot a surface like ellipsoid with plotly 3D?Currently only surfaces of the form z=f(x,y) are discussed in the docs. There is also Mesh 3D, but I found no examples for it. It seem…

PyTorch DataLoader uses same random seed for batches run in parallel

There is a bug in PyTorch/Numpy where when loading batches in parallel with a DataLoader (i.e. setting num_workers > 1), the same NumPy random seed is used for each worker, resulting in any random f…

How to fix 502 Bad Gateway Error in production(Nginx)?

When I tried to upload a big csv file of size about 600MB in my project which is hosted in the digital ocean, it tries to upload but shows 502 Bad Gateway Error (Nginx). The application is a data conve…

Shift theorem in Discrete Fourier Transform

Im trying to solve a problem with python+numpy in which Ive some functions of type that I need to convolve with another function . In order to optimize code, I performed the fft of f and g, I multipli…

Running pudb inside docker container

I prefer pudb for python debugging. I am building python applications that run inside docker container. Does any one know how to make pudb available inside docker container?Thank you

Argparse: defaults from file

I have a Python script which takes a lot of arguments. I currently use a configuration.ini file (read using configparser), but would like to allow the user to override specific arguments using command …

How can access Uploaded File in Google colab

Im new in python and I use Google Colab . I uploaded a train_data.npy into google Colab and then I want to use it . According to this link How to import and read a shelve or Numpy file in Google Colabo…

__add__ to support addition of different types?

Would be very easy to solve had python been a static programming language that supported overloading. I am making a class called Complex which is a representation of complex numbers (I know python has …

How to open .ndjson file in Python?

I have .ndjson file that has 20GB that I want to open with Python. File is to big so I found a way to split it into 50 peaces with one online tool. This is the tool: https://pinetools.com/split-files N…