Save cx_freeze errors - python

So when a python program has been frozen using cx_freeze it opens up an alert whenever the program crashes the only problem is the only way to distribute the traceback (for bug reports) is by screenshot-ting the alert box which is a bit of a pain (you can't copy text from the alert box).
Is there any way to save cx_freeze error reports? For example by writing them into a crash-log file. It seams a shame to present the crashes in such a helpful way and yet have no way of easily sending crash reports to developers (screenshot-ting being a but tedious).

I think it is actually possible to copy the text from a Windows message box, but I agree that it's not obvious to users that you can do that.
It should be possible to set sys.excepthook to a function that saves the error and traceback somewhere. This will stop cx_Freeze displaying the error message box, so it's up to you to notify the user about errors if that's appropriate.

Related

Python quit upon hitting the debug point, throw "called Tcl_FindHashEntry on deleted table" Error

I am running my Python script using Pycharm on Mac.
The script is reading, processing and plotting some data.
When I place a debug point(often shortly after I plotted some charts), I encountered "python quit unexpectedly". My debugger logged:
"called Tcl_FindHashEntry on deleted table"
Would you please help? I want the program to stop at the debug point, instead of quitting.
Your error looks like its coming from the backend of MatPlotLib. Here is an open bug which references the same error. The bug may or may not be what you are experiencing, but has to do with window sizing and multiple screens.
As troubleshooting:
If multiple monitors or a dock are in use, try removing them from the equation.
Use Windows to examine breakpoint. (Bug appears Mac-specific.)

Python program crashes when opening from installer, but not if script is run from Spyder IDE

something weird is going on. I have created a program with PyQt that when opened in Spyder works flawlessly. However if I create the installer with Pyinstall and run it, the program opens normally but once I click on a cell of a table from the main window, it crashes (so I think it has to do with the mousePressEvent() method?
Is there a way where I can debug it, or know where the error is exactly? Because when it crashes the only thing I get is a message of 'Python has stopped working'.
I do have some try blocks around the code and as I said, when opened from the IDE the whole program works as expected.
Please let me know if you need more info
Thanks
EDIT: For a bit more context, if I put the whole mousePressEvent() method in a try block it will still crash when I click the on a cell of the table
Have you include your external resource (like a image) in PyInstaller with the right path folder ? like in this link and have adapt your code ? https://pythonhosted.org/PyInstaller/spec-files.html#adding-data-files ?

How do I handle errors in Ren'py

I'm making a game using Ren'py (based on python) and most errors aren't shown, especially the errors in python code. Is there a possibility to check for possible errors at compile time and how do I get where some errors occur? If there are errors the game normally doesn't run or breaks at the a errors appearance without a message.Is there maybe a file, where they are written in or something like that? Or do I have to debug using logs everywhere?
Compile errors will be shown when you first try to compile the RPY files. They will be put in "errors.txt" in your project directory. Most errors are not found at compile-time, however, and will only show up once you encounter them at run-time.
You can use Lint to check for some common errors (It's called "Check Script (Lint)"), but mostly you'll have to playtest to ensure there are no errors. Errors during playback should pop up a gray screen showing the error and traceback with the option to Ignore, Rollback, or Quit. Is this screen not showing up for you?
If you're looking for some kind of intellisense like you have for some languages, where as you write the code the IDE shows errors, then it doesn't exist. You have to launch the game so that the code is compiled, just then Ren'py will show you errors. You can see them in the editor or in the errors.txt that Ren'Py creates. To test you python code you can launch the game and type Shift + O to open the console.

twisted reactor.spawnProcess opens an unwanted console when cx_freeze'd

Basically it's all in the title, when I run the code from a console (on Windows) the child process runs without opening another console, but when I run the code from the cx_freeze'd app another console opens.
I found this old thread where was suggested to use FreeConsole(), it will flash the console on screen for a blink but I can eventually live with it, unfortunately if i understood correctly it should be called from the child process.
http://twistedmatrix.com/pipermail/twisted-python/2007-February/014738.html
I also found this ticket (7yo) on a re-factoring of the whole spawnProcess on windows but apparently it never happened:
http://twistedmatrix.com/trac/ticket/2415
I have no control over the code of the child process, so doing something there is unfortunately not an option, but even if I did the process I'm spawning it's a console app and I believe FreeConsole() could not be called there or the process will terminate.
This is possibly a bug in Twisted, but possibly a bug in cx_Freeze.
What happens when you run the code from the GUI with Python, but without cx_Freeze involved? You should be able to test this if you have Python installed by simply putting your code into a .pyw file and double-clicking on it in Explorer.
If this still pops up a console window when you run your subprocess, then this is totally a bug in Twisted and you should file it as such. Eric's answer in that mailing list message is wrong; if you want to spawn processes with spawnProcess they definitely shouldn't be popping up random console windows.
If the click-on-a-.pyw launching method doesn't cause a console window to pop up, then it's probably something about the way cx_Freeze has constructed your executable and you might want to look at it.
On UNIX, we have a platform-specific usePTY, so it makes sense that we could expand spawnProcess with a platform-specific useConsole that would do something analogous for Windows. This later message in the thread suggests an implementation strategy, so please file a ticket. The let's-redo-everything ticket is too ambitious to fix this one issue.

I'm new to Python and managed to crash IDLE after adding a line of code to my program

I'm working on a small game and, in the interest of full disclosure, I've learned some other languages before but this is only my second day learning Python.
What I was trying to do was simple enough: I was trying to generate a random integer between two integer values (e.g. random(a,b)). I looked around to see if there was an existing function that I could use, and I found information about a function called "randint". So I added a line of code to my program that looked something like:
value = randint(1,15)
I received an error that randint was undefined. So then I looked further and saw someone state that I needed to import the random library using the following line of code:
import random
The moment I refreshed (F5) IDLE crashed. So then I figured "welp, that was wrong" and I went to open IDLE and make the change. I was able to open IDLE, but I can't open the file. In fact, I can't open any of the (three) files that I've made. I opened the file in Notepad++ and removed the offending lines (both randint and import random), but IDLE still crashes whenever I try to open a file. I rebooted my laptop for lack of a better idea, but there was no change in behavior.
Details: Windows 7 x64 w/ all updates, Python 3.2.3.
...help? Also, what did I do? :-/
Received a solution from another forum:
"If you want to try diagnosing the problem, run the Python command line and then enter the line:
from idlelib import idle
That will launch idle, and you should get a traceback in the command prompt if something goes wrong."
When I did this it opened IDLE and produced an error (displayed in terminal) when I tried to open the file. Rather than crashing, I received a prompt (pop-up, not in terminal) to save the file. I found this odd because I had just opened it and hadn't made any changes. I let it save the file and then success! Now I can use IDLE to open any of my files again. Hope this helps someone else who encounters this issue :)
I'm not sure if this is helpful, but based on my experience, IDLE was never reliable enough for me. Practice using the command-line Python instead.
Go to the command prompt by running cmd
cd into your file's directory
type python yourfilename.py

Categories