views:

26

answers:

1

I have a Python C API extension module which occassionally falls over with an uninformative "MemoryError". It's clearly not an error that's catered for by the module's exception handlers. How do I get a more informative error traceback so I can figure out what's gone wrong in the extension module?

Perhaps the question should be, given that I do have the extension module source code, what should I do to get a debuggable version of it with MSVC on MS Windows?

+2  A: 

Looks like the extension module is claiming to be out of memory -- whether that's true or false, of course, it's impossible to tell without looking at the extension's sources. Just in case it's true, so that the scarcity of memory might impede a traceback, an old trick is to get some memory earlier and drop it in the error case before reraising it, e.g:

reserve = [None] * 10000
try: amodule.somecall()
except MemoryError:
    del reserve
    raise

This won't tell you much more than which Python-visible function raised the error (and what Python function called it, etc). To go beyond that you'll need to compile the extension's C sources for debugging and use some tools such as gdb.

Alex Martelli
Yes, you are right. I've edited my question. What I actually want to do is debug the module given that I know which python call has triggered that error.
TheObserver