pythonpython-3.4stack-tracecx-freezefaulthandler

Get Python stack trace while using cx_freeze


I have a data acquisition program written in Python that I distribute to my collaboration as an executable (using cx_freeze), as I don't want to bother them with installing Python and installing all the software dependencies. The program has been working well for a year now. Recently, the program started to crash (crash, not give a scripting error, i.e., the Python virtual machine itself is crashing). So I would like to know what library is causing this problem. This problem is happening randomly, so it's difficult to systematically pinpoint the cause.

I learned about faulthandler, and I would like to use it with my cx_freeze, because I can't be sure the problem is happening due to cx_freeze itself or due to some other library.

The question: How can I produce a cx_freeze executable that will use faulthandler?

What I tried:

My current cx_freeze setup script is the following:

import sys
from cx_Freeze import setup, Executable
from GUI.Meta import *

target = Executable("Main.py",
                    #base = "Win32GUI",
                    icon = "GUI\\icon.ico",
                    compress=True,
                    targetName="Prog.exe")

setup(
    name = "My Software",
    version = SOFTWARE_VERSION,
    description = "",
    executables = [target])

I tried replacing my Executable part Main.py by Main.py -q -X faulthandler, but that didn't work. Importing faulthandler in my cx_freeze setup file with import faulthandler or from faulthandler import * didn't help.

Please advise.

Additional info: Dependencies that I'm using (in case you may know a possible cause of the problem): PySide, Sympy, Numpy, H5py, PySerial, Matplotlib


Solution

  • I learned that I could use procdump. It can be downloaded from here. It's a very simple program that can log stack trace. You can use it with:

    C:\>procdump -ma -i c:\Dumps
    

    and this will dump the stack trace of any program that crashes to that folder.