You too can learn from my mistakes

Published December 26, 2004
Advertisement
I was working on a C++ project that I just started adding embedded Python support to, and I while testing the Python exception handling I kept getting these strange errors Fatal Python error: unexpected exception during garbage collection when generating Python exceptions, and I just couldn't figure out where that was coming from.

Long story short: I had wrapped Py_Initialize() and Py_Finalize() in a class' constructor and destructor to apply RAII so I wouldn't forget to call Py_Finalize(). Unfortunately, I had created an instance of the class inside the try block that I was using to handle the exceptions. So when the exception was thrown, the stack unwound and Py_Finalize() was called while Python had it's pants down (metaphorically speaking). Boom.

The irony is that the problem only showed up in test code, and wouldn't have been a factor in any of the actual usages in the application because of the way that I was initializing Python. At least, I now know one possible cause for that kind of error, and have something to look for the next time I see something like it.
Previous Entry I'm such a geek
Next Entry Yay
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

New bug to me

1910 views

Week/Class 9

1740 views

Week/Class 8

1788 views

Week/Class 7

1835 views

The promised files

2115 views

Week/Class 6

1518 views

Week/Session 5

1578 views

Week/Session 4

1519 views

On the soapbox

1636 views

Week/Session 3

1493 views
Advertisement