2

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

The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
  • base = None; if sys.platform == "win32":; base = "Win32GUI"; from : http://cx-freeze.readthedocs.io/en/latest/distutils.html#distutils-setup-script , if cmd under windows: base="console" (french name) – Destrif Jul 04 '16 at 14:48
  • @Destrif I'm sorry, how will faulthandler come here into play? – The Quantum Physicist Jul 04 '16 at 15:05
  • @Destrif Not necessarily an import problem. Actually imports seem wrong, because `faulthandler` usually is called on Python command line using `Python Main.py -q -X faulthandler`. Without `faulthandler`, there's no problem whatsoever. So my question is about how to get the stacktrace of my program while using cx_freeze. – The Quantum Physicist Jul 04 '16 at 15:15
  • Ok so perfect: python version/Os – Destrif Jul 04 '16 at 15:17
  • @Destrif Python 3.4 32-bit on Windows 10. I use Anaconda with Python 3.4 environment. – The Quantum Physicist Jul 04 '16 at 15:22
  • Optional(http://sebsauvage.net/python/snyppets/#py2exe), see also: https://docs.python.org/3/library/sys.html#sys.excepthook , don't find anything relevant... So I'll let some-else do better. – Destrif Jul 04 '16 at 15:29
  • @Destrif Thanks for trying. – The Quantum Physicist Jul 04 '16 at 15:31
  • numpy may need some dll libraries that might be missing from your application build, http://stackoverflow.com/a/34893933/5781248 – J.J. Hakala Jul 04 '16 at 21:43
  • @J.J.Hakala but if that was the case, then the crash won't be random, right? It would immediately crash when numpy is used – The Quantum Physicist Jul 04 '16 at 21:46
  • @TheQuantumPhysicist I don't know if it depends on what numpy methods are called. Maybe calling `x = numpy.arange(-50, 50, 0.1); y = numpy.sin(x)` at the beginning of the program would suffice as a quick test. – J.J. Hakala Jul 04 '16 at 21:57
  • @J.J.Hakala well, my program keeps working for hours before it crashes (if it crashes... It's that random)... The same functions are called periodically again and again... – The Quantum Physicist Jul 04 '16 at 22:00

1 Answers1

0

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.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189