[IPython-dev] Re: [IPython-user] A plea for help with a threading bug...

Andrew Straw astraw at caltech.edu
Fri Mar 18 23:03:43 CST 2005


I'm not sure how to run GDB with ipython, but with straight Python, do 
this:

Use a debug build of Python, and use it to build all extension modules 
so that all debugging symbols are included.  Copy 
Python-2.x/Misc/gdbinit to .gdbinit.  Run gdb.  Then type "target exec 
/path/to/your/debug/build/of/python" now type "run yourscript.py any 
args here".

Your program should now be running under gdb.  When a segfault happens, 
you can get a backtrace of the C stack (type "bt"), but you can also 
get a python stack backtrace with the magic provided by .gdbinit.  It's 
been a little while, but you type something like "up 2" do move 
yourself up the stack to a C call like "Py_Eval".  This Py_Eval 
(whatever it's really called) is the name of the C function that 
executes the Python bytecode.  So, once you're here you can execute the 
.gdbinit macros like "pyframe" and "pystack".  This way, you can find 
the Python stack the resulted in the bad call.

IIRC, gdb will tell you which thread crashed, which are running, and so 
on.  This may help track down the problem.

If the problem really is that some code was using the Python C API 
while the GIL is released (between Py_BEGIN_ALLOW_THREADS and 
Py_END_END_THREADS), all of this fancy debugging will probably only 
reveal the innards of some bit of code that eventually crashed, not 
necessarily the culprit.  Something like this could happen, for 
example, if one thread de-references an object which then gets 
de-alloced, but a call from another thread also de-references it 
without having acquired the GIL.

Hope that helps...
Andrew

On Mar 18, 2005, at 7:10 PM, Fernando Perez wrote:

>> Subject: Re: [IPython-user] A plea for help with a threading bug...
>> From:  Andrew Straw <astraw at caltech.edu>
>> Date: Fri, 18 Mar 2005 19:01:37 -0800
>> To:  IPython-dev List <ipython-dev at scipy.net>> Well, since you asked, 
>> here's a guess:
>> Make sure there are no calls happening to the Python C API between 
>> Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS.  If ipython is pure 
>> Python, then this would suggest a problem with some other code 
>> written in C.
>> HTH,
>> Andrew
>
> Well, ipython _is_ 100% pure, pristine python code.  <TAB> calls the 
> completion code, which ultimately will peek into the readline module, 
> which does have a C component.  But that's part of python itself, not 
> my code.
>
> The question is, how in the world do I file a bug report against 
> python on this, when I don't even know who may be causing it?  
> readline may not be the culprit: there are also pygtk and wx calls 
> being made in there...
>
> I hate threads.  I hate threads.  I hate threads.
>
> Thanks, though.
>
> f
>





More information about the IPython-dev mailing list