Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when using memory allocation tracker #4834

Closed
letmaik opened this issue Jul 1, 2014 · 15 comments · Fixed by #4841
Closed

Segmentation fault when using memory allocation tracker #4834

letmaik opened this issue Jul 1, 2014 · 15 comments · Fixed by #4841

Comments

@letmaik
Copy link

letmaik commented Jul 1, 2014

I use Python 2.7.6, numpy 1.8.1 and cython 0.20.2 under Red Hat 6.5. I tried out the code in numpy/tools/allocation_tracking, that is, I installed the extension (alloc_hook) and then copied track_allocations.py into my own code and used it according to the example in the main block. But the moment I allocate a numpy array I get a segmentation fault. In case it is related, here is the extension compile output:

(p27)-bash-4.1$ python setup.py install
running install
running build
running build_ext
cythoning alloc_hook.pyx to alloc_hook.c
warning: alloc_hook.pyx:30:18: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
warning: alloc_hook.pyx:30:29: Non-trivial type declarators in shared declaration (e.g. mix of pointers and values). Each pointer declaration should be on its own line.
building 'alloc_hook' extension
creating build
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/Python2.7/lib/python2.7/site-packages/numpy/core/include -I/opt/Python2.7/include/python2.7 -c alloc_hook.c -o build/temp.linux-x86_64-2.7/alloc_hook.o
In file included from /opt/Python2.7/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1761,
                 from /opt/Python2.7/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17,
                 from /opt/Python2.7/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from alloc_hook.c:352:
/opt/Python2.7/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
/opt/Python2.7/lib/python2.7/site-packages/numpy/core/include/numpy/__ufunc_api.h:241: warning: ‘_import_umath’ defined but not used
creating build/lib.linux-x86_64-2.7
gcc -pthread -shared build/temp.linux-x86_64-2.7/alloc_hook.o -L/opt/Python2.7/lib -lpython2.7 -o build/lib.linux-x86_64-2.7/alloc_hook.so
running install_lib
copying build/lib.linux-x86_64-2.7/alloc_hook.so -> ...

@thouis @charris

@juliantaylor
Copy link
Contributor

can you provide a backtrace with gdb? or provide the code snippet that crashes.
the numpy provided track_allocations.py works for me so we need more information to reproduce it.

@letmaik
Copy link
Author

letmaik commented Jul 2, 2014

I need a bit more time to reproduce/isolate it. The example shipped with track_allocations.py works for me as well.

@letmaik
Copy link
Author

letmaik commented Jul 3, 2014

Ok I have more details but couldn't isolate the error completely yet. Contrary to what I said earlier it doesn't happen the first time an array is allocated. My program actually runs a while, calculating things, plotting things (with Matplotlib/Basemap) and at one point when it wants to draw a map with Basemap it seg faults:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000003 in ?? ()
backtrace
#0  0x0000000000000003 in ?? ()
#1  0x00007fffd995c576 in GEOSGeom_destroy_r (extHandle=0x3c43980, a=<optimized out>) at geos_ts_c.cpp:2175
#2  0x00007fffd9b76869 in __pyx_pf_8_geoslib_12BaseGeometry_18__dealloc__ (__pyx_v_self=0x8047950) at src/_geoslib.c:2932
#3  __pyx_pw_8_geoslib_12BaseGeometry_19__dealloc__ (__pyx_v_self=0x8047950) at src/_geoslib.c:2909
#4  __pyx_tp_dealloc_8_geoslib_BaseGeometry (o=0x8047950) at src/_geoslib.c:4288
#5  0x00007ffff7b2c7fa in delete_garbage (old=0x7ffff7dc2090 <generations+48>, collectable=0x7fffffffaf10) at Modules/gcmodule.c:821
#6  collect (generation=0) at Modules/gcmodule.c:984
#7  0x00007ffff7b2ce9e in collect_generations () at Modules/gcmodule.c:1050
#8  _PyObject_GC_Malloc (basicsize=<optimized out>) at Modules/gcmodule.c:1511
#9  0x00007ffff7b2cefe in _PyObject_GC_NewVar (tp=<optimized out>, nitems=2) at Modules/gcmodule.c:1531
#10 0x00007ffff7aa571f in PyTuple_New (size=2) at Objects/tupleobject.c:90
#11 0x00007ffff7a87fdb in dict_items (mp=0x620700) at Objects/dictobject.c:1307
#12 0x00007ffff7af3e11 in call_function (oparg=<optimized out>, pp_stack=0x7fffffffb0d8) at Python/ceval.c:4005
#13 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#14 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0xa58f30, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=2, kws=0x4ba9948, kwcount=0, defs=0xa7e6e8, defcount=1, closure=0x0) at Python/ceval.c:3253
#15 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=2, n=<optimized out>, pp_stack=0x7fffffffb2d8, func=0xa910c8)
    at Python/ceval.c:4117
#16 call_function (oparg=<optimized out>, pp_stack=0x7fffffffb2d8) at Python/ceval.c:4042
#17 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#18 0x00007ffff7af4a7e in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7fffffffb428, func=0xa91140)
    at Python/ceval.c:4107
#19 call_function (oparg=<optimized out>, pp_stack=0x7fffffffb428) at Python/ceval.c:4042
#20 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#21 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0xa60030, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=2, kws=0x4c3c998, kwcount=0, defs=0xa8dc28, defcount=1, closure=0x0) at Python/ceval.c:3253
#22 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=2, n=<optimized out>, pp_stack=0x7fffffffb628, func=0xa816e0)
    at Python/ceval.c:4117
#23 call_function (oparg=<optimized out>, pp_stack=0x7fffffffb628) at Python/ceval.c:4042
#24 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#25 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0xa60130, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=2, kws=0x4c02ad8, kwcount=0, defs=0xa8dbe8, defcount=1, closure=0x0) at Python/ceval.c:3253
#26 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=2, n=<optimized out>, pp_stack=0x7fffffffb828, func=0xa81b90)
    at Python/ceval.c:4117
#27 call_function (oparg=<optimized out>, pp_stack=0x7fffffffb828) at Python/ceval.c:4042
#28 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#29 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0xa602b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=0, kws=0x4c09a58, kwcount=0, defs=0xa8de28, defcount=1, closure=0x0) at Python/ceval.c:3253
#30 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=0, n=<optimized out>, pp_stack=0x7fffffffba28, func=0xa81c80)
    at Python/ceval.c:4117
#31 call_function (oparg=<optimized out>, pp_stack=0x7fffffffba28) at Python/ceval.c:4042
#32 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#33 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4450c30, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=1, kws=0x4c17660, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#34 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7fffffffbc28, func=0x44516e0)
    at Python/ceval.c:4117
#35 call_function (oparg=<optimized out>, pp_stack=0x7fffffffbc28) at Python/ceval.c:4042
#36 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#37 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4450cb0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=1, kws=0x4c3bd08, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#38 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7fffffffbe28, func=0x4451758)
    at Python/ceval.c:4117
#39 call_function (oparg=<optimized out>, pp_stack=0x7fffffffbe28) at Python/ceval.c:4042
#40 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#41 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4450b30, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=2, kws=0x4da21f8, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#42 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=2, n=<optimized out>, pp_stack=0x7fffffffc028, func=0x44515f0)
    at Python/ceval.c:4117
#43 call_function (oparg=<optimized out>, pp_stack=0x7fffffffc028) at Python/ceval.c:4042
#44 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#45 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4450a30, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=4, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#46 0x00007ffff7a73e21 in function_call (func=0x4451500, arg=0x1113a310, kw=0x0) at Objects/funcobject.c:526
#47 0x00007ffff7a449a3 in PyObject_Call (func=0x4451500, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2529
#48 0x00007ffff7a570cf in instancemethod_call (func=0x4451500, arg=0x1113a310, kw=0x0) at Objects/classobject.c:2602
#49 0x00007fffd3f8afac in __Pyx_PyObject_Call (kw=0x0, arg=0x882b5f0, func=0x4591d70) at alloc_hook.c:4093
#50 __pyx_f_10alloc_hook_pyhook (__pyx_v_old=<optimized out>, __pyx_v_new=<optimized out>, __pyx_v_size=<optimized out>, 
    __pyx_v_user_data=0x4591d70) at alloc_hook.c:1357
#51 0x00007fffead55b54 in PyDataMem_FREE (ptr=0x10cae5a0) at numpy/core/src/multiarray/multiarraymodule.c:3545
#52 0x00007fffeac91b04 in array_dealloc (self=0x10fc1250) at numpy/core/src/multiarray/arrayobject.c:417
#53 0x00007fffd9b768ba in __pyx_tp_dealloc_8_geoslib_BaseGeometry (o=0x8047950) at src/_geoslib.c:4293
#54 0x00007ffff7af22d1 in PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:1137
#55 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x3bdc3b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=2, kws=0x5539a80, kwcount=1, defs=0x3bf7868, defcount=1, closure=0x0) at Python/ceval.c:3253
#56 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=2, n=<optimized out>, pp_stack=0x7fffffffc7f8, func=0x3e920c8)
    at Python/ceval.c:4117
#57 call_function (oparg=<optimized out>, pp_stack=0x7fffffffc7f8) at Python/ceval.c:4042
#58 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#59 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x3bdc1b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=1, kws=0x43849c0, kwcount=8, defs=0x2a6f1b8, defcount=35, closure=0x0) at Python/ceval.c:3253
#60 0x00007ffff7a73f28 in function_call (func=0x3beaed8, arg=0x11052610, kw=0x10f281a0) at Objects/funcobject.c:526
#61 0x00007ffff7a449a3 in PyObject_Call (func=0x3beaed8, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2529
#62 0x00007ffff7a570cf in instancemethod_call (func=0x3beaed8, arg=0x11052610, kw=0x10f281a0) at Objects/classobject.c:2602
#63 0x00007ffff7a449a3 in PyObject_Call (func=0x55787d0, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2529
#64 0x00007ffff7ab0cc0 in slot_tp_init (self=0x11047a10, args=0x7ffff7fac050, kwds=0x10f281a0) at Objects/typeobject.c:5692
#65 0x00007ffff7aa7858 in type_call (type=<optimized out>, args=0x7ffff7fac050, kwds=0x10f281a0) at Objects/typeobject.c:745
#66 0x00007ffff7a449a3 in PyObject_Call (func=0x3f81ca0, arg=<optimized out>, kw=<optimized out>) at Objects/abstract.c:2529
#67 0x00007ffff7af34cd in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7fffffffcdf8, func=0x3f81ca0) at Python/ceval.c:4239
#68 call_function (oparg=<optimized out>, pp_stack=0x7fffffffcdf8) at Python/ceval.c:4044
#69 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#70 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x33ae0b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=7, kws=0x4d087f8, kwcount=6, defs=0x3ff2618, defcount=7, closure=0x0) at Python/ceval.c:3253
#71 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=7, n=<optimized out>, pp_stack=0x7fffffffcff8, func=0x417c2a8)
    at Python/ceval.c:4117
#72 call_function (oparg=<optimized out>, pp_stack=0x7fffffffcff8) at Python/ceval.c:4042
#73 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#74 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x332aab0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=2, kws=0x4a21780, kwcount=5, defs=0x3be2e00, defcount=22, closure=0x0) at Python/ceval.c:3253
#75 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=2, n=<optimized out>, pp_stack=0x7fffffffd1f8, func=0x4179f50)
    at Python/ceval.c:4117
#76 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd1f8) at Python/ceval.c:4042
#77 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#78 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x43892b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=2, kws=0x47a71f8, kwcount=0, defs=0x0, defcount=0, closure=0x48dcb48) at Python/ceval.c:3253
#79 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=2, n=<optimized out>, pp_stack=0x7fffffffd3f8, func=0x61bca28)
    at Python/ceval.c:4117
#80 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd3f8) at Python/ceval.c:4042
#81 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#82 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4389b30, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=1, kws=0x478a250, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#83 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7fffffffd5f8, func=0x43856e0)
    at Python/ceval.c:4117
#84 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd5f8) at Python/ceval.c:4042
#85 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#86 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7ed3eb0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=1, kws=0x785f78, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#87 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7fffffffd7f8, func=0x44518c0)
    at Python/ceval.c:4117
#88 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd7f8) at Python/ceval.c:4042
#89 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#90 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7ec1cb0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=0, kws=0x2cdd3a0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#91 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=0, n=<optimized out>, pp_stack=0x7fffffffd9f8, func=0x4451320)
    at Python/ceval.c:4117
#92 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd9f8) at Python/ceval.c:4042
#93 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#94 0x00007ffff7af4a7e in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7fffffffdb48, 
    func=0x4451a28) at Python/ceval.c:4107
#95 call_function (oparg=<optimized out>, pp_stack=0x7fffffffdb48) at Python/ceval.c:4042
#96 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#97 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7f09b30, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#98 0x00007ffff7af5c92 in PyEval_EvalCode (co=<optimized out>, globals=<optimized out>, locals=<optimized out>) at Python/ceval.c:667
#99 0x00007ffff7b15880 in run_mod (arena=0x8af350, flags=0x0, locals=0x63e450, globals=0x63e450, filename=<optimized out>, mod=0x6adec0)
    at Python/pythonrun.c:1370
#100 PyRun_FileExFlags (fp=0x785db0, filename=<optimized out>, start=<optimized out>, globals=0x63e450, locals=0x63e450, closeit=1, 
    flags=0x0) at Python/pythonrun.c:1356
#101 0x00007ffff7aec803 in builtin_execfile (self=<optimized out>, args=<optimized out>) at Python/bltinmodule.c:803
#102 0x00007ffff7af4000 in call_function (oparg=<optimized out>, pp_stack=0x7fffffffdec8) at Python/ceval.c:4021
#103 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#104 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7ee21b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=3, kws=0x804948, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#105 0x00007ffff7af3d2a in fast_function (nk=<optimized out>, na=3, n=<optimized out>, pp_stack=0x7fffffffe0c8, func=0x7a91b8)
    at Python/ceval.c:4117
#106 call_function (oparg=<optimized out>, pp_stack=0x7fffffffe0c8) at Python/ceval.c:4042
#107 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#108 0x00007ffff7af4a7e in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>, pp_stack=0x7fffffffe218, 
    func=0x79d488) at Python/ceval.c:4107
#109 call_function (oparg=<optimized out>, pp_stack=0x7fffffffe218) at Python/ceval.c:4042
#110 PyEval_EvalFrameEx (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2666
#111 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7f017b0, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, 
    argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#112 0x00007ffff7af5c92 in PyEval_EvalCode (co=<optimized out>, globals=<optimized out>, locals=<optimized out>) at Python/ceval.c:667
#113 0x00007ffff7b15880 in run_mod (arena=0x66cdc0, flags=0x7fffffffe510, locals=0x63e450, globals=0x63e450, filename=<optimized out>, 
    mod=0x6960f0) at Python/pythonrun.c:1370
#114 PyRun_FileExFlags (fp=0x6a7420, filename=<optimized out>, start=<optimized out>, globals=0x63e450, locals=0x63e450, closeit=1, 
    flags=0x7fffffffe510) at Python/pythonrun.c:1356
#115 0x00007ffff7b15a5f in PyRun_SimpleFileExFlags (fp=0x6a7420, filename=0x7fffffffe881 "/my/python/script", 
    closeit=1, flags=0x7fffffffe510) at Python/pythonrun.c:948
#116 0x00007ffff7b2b5d4 in Py_Main (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:640
#117 0x00007ffff6ddfd1d in __libc_start_main () from /lib64/libc.so.6
#118 0x0000000000400649 in _start ()

@njsmith
Copy link
Member

njsmith commented Jul 3, 2014

You might try valgrind. It tends to throw up false positives when used with
python, but this sounds like the kind of issue that it's good at diagnosing.
On 3 Jul 2014 13:24, "Maik Riechert" notifications@github.com wrote:

Ok I have more details but couldn't isolate the error completely yet.
Contrary to what I said earlier it doesn't happen the first time an
array is allocated. My program actually runs a while, calculating things,
plotting things (with Matplotlib/Basemap) and at one point when it wants to
draw a map with Basemap it seg faults:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000003 in ?? ()
backtrace
#0 0x0000000000000003 in ?? ()
#1 0x00007fffd995c576 in GEOSGeom_destroy_r (extHandle=0x3c43980, a=) at geos_ts_c.cpp:2175
#2 0x00007fffd9b76869 in pyx_pf_8_geoslib_12BaseGeometry_18__dealloc (pyx_v_self=0x8047950) at src/_geoslib.c:2932
#3 __pyx_pw_8_geoslib_12BaseGeometry_19__dealloc
(__pyx_v_self=0x8047950) at src/_geoslib.c:2909
#4 __pyx_tp_dealloc_8_geoslib_BaseGeometry (o=0x8047950) at src/_geoslib.c:4288
#5 0x00007ffff7b2c7fa in delete_garbage (old=0x7ffff7dc2090 <generations+48>, collectable=0x7fffffffaf10) at Modules/gcmodule.c:821
#6 collect (generation=0) at Modules/gcmodule.c:984
#7 0x00007ffff7b2ce9e in collect_generations () at Modules/gcmodule.c:1050
#8 _PyObject_GC_Malloc (basicsize=) at Modules/gcmodule.c:1511
#9 0x00007ffff7b2cefe in _PyObject_GC_NewVar (tp=, nitems=2) at Modules/gcmodule.c:1531
#10 0x00007ffff7aa571f in PyTuple_New (size=2) at Objects/tupleobject.c:90
#11 0x00007ffff7a87fdb in dict_items (mp=0x620700) at Objects/dictobject.c:1307
#12 0x00007ffff7af3e11 in call_function (oparg=, pp_stack=0x7fffffffb0d8) at Python/ceval.c:4005
#13 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#14 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0xa58f30, globals=, locals=, args=,
argcount=2, kws=0x4ba9948, kwcount=0, defs=0xa7e6e8, defcount=1, closure=0x0) at Python/ceval.c:3253
#15 0x00007ffff7af3d2a in fast_function (nk=, na=2, n=, pp_stack=0x7fffffffb2d8, func=0xa910c8)
at Python/ceval.c:4117
#16 call_function (oparg=, pp_stack=0x7fffffffb2d8) at Python/ceval.c:4042
#17 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#18 0x00007ffff7af4a7e in fast_function (nk=, na=, n=, pp_stack=0x7fffffffb428, func=0xa91140)
at Python/ceval.c:4107
#19 call_function (oparg=, pp_stack=0x7fffffffb428) at Python/ceval.c:4042
#20 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#21 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0xa60030, globals=, locals=, args=,
argcount=2, kws=0x4c3c998, kwcount=0, defs=0xa8dc28, defcount=1, closure=0x0) at Python/ceval.c:3253
#22 0x00007ffff7af3d2a in fast_function (nk=, na=2, n=, pp_stack=0x7fffffffb628, func=0xa816e0)
at Python/ceval.c:4117
#23 call_function (oparg=, pp_stack=0x7fffffffb628) at Python/ceval.c:4042
#24 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#25 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0xa60130, globals=, locals=, args=,
argcount=2, kws=0x4c02ad8, kwcount=0, defs=0xa8dbe8, defcount=1, closure=0x0) at Python/ceval.c:3253
#26 0x00007ffff7af3d2a in fast_function (nk=, na=2, n=, pp_stack=0x7fffffffb828, func=0xa81b90)
at Python/ceval.c:4117
#27 call_function (oparg=, pp_stack=0x7fffffffb828) at Python/ceval.c:4042
#28 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#29 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0xa602b0, globals=, locals=, args=,
argcount=0, kws=0x4c09a58, kwcount=0, defs=0xa8de28, defcount=1, closure=0x0) at Python/ceval.c:3253
#30 0x00007ffff7af3d2a in fast_function (nk=, na=0, n=, pp_stack=0x7fffffffba28, func=0xa81c80)
at Python/ceval.c:4117
#31 call_function (oparg=, pp_stack=0x7fffffffba28) at Python/ceval.c:4042
#32 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#33 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4450c30, globals=, locals=, args=,
argcount=1, kws=0x4c17660, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#34 0x00007ffff7af3d2a in fast_function (nk=, na=1, n=, pp_stack=0x7fffffffbc28, func=0x44516e0)
at Python/ceval.c:4117
#35 call_function (oparg=, pp_stack=0x7fffffffbc28) at Python/ceval.c:4042
#36 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#37 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4450cb0, globals=, locals=, args=,
argcount=1, kws=0x4c3bd08, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#38 0x00007ffff7af3d2a in fast_function (nk=, na=1, n=, pp_stack=0x7fffffffbe28, func=0x4451758)
at Python/ceval.c:4117
#39 call_function (oparg=, pp_stack=0x7fffffffbe28) at Python/ceval.c:4042
#40 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#41 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4450b30, globals=, locals=, args=,
argcount=2, kws=0x4da21f8, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#42 0x00007ffff7af3d2a in fast_function (nk=, na=2, n=, pp_stack=0x7fffffffc028, func=0x44515f0)
at Python/ceval.c:4117
#43 call_function (oparg=, pp_stack=0x7fffffffc028) at Python/ceval.c:4042
#44 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#45 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4450a30, globals=, locals=, args=,
argcount=4, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#46 0x00007ffff7a73e21 in function_call (func=0x4451500, arg=0x1113a310, kw=0x0) at Objects/funcobject.c:526
#47 0x00007ffff7a449a3 in PyObject_Call (func=0x4451500, arg=, kw=) at Objects/abstract.c:2529
#48 0x00007ffff7a570cf in instancemethod_call (func=0x4451500, arg=0x1113a310, kw=0x0) at Objects/classobject.c:2602
#49 0x00007fffd3f8afac in __Pyx_PyObject_Call (kw=0x0, arg=0x882b5f0, func=0x4591d70) at alloc_hook.c:4093
#50 __pyx_f_10alloc_hook_pyhook (__pyx_v_old=, __pyx_v_new=, __pyx_v_size=,
__pyx_v_user_data=0x4591d70) at alloc_hook.c:1357
#51 0x00007fffead55b54 in PyDataMem_FREE (ptr=0x10cae5a0) at numpy/core/src/multiarray/multiarraymodule.c:3545
#52 0x00007fffeac91b04 in array_dealloc (self=0x10fc1250) at numpy/core/src/multiarray/arrayobject.c:417
#53 0x00007fffd9b768ba in __pyx_tp_dealloc_8_geoslib_BaseGeometry (o=0x8047950) at src/_geoslib.c:4293
#54 0x00007ffff7af22d1 in PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:1137
#55 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x3bdc3b0, globals=, locals=, args=,
argcount=2, kws=0x5539a80, kwcount=1, defs=0x3bf7868, defcount=1, closure=0x0) at Python/ceval.c:3253
#56 0x00007ffff7af3d2a in fast_function (nk=, na=2, n=, pp_stack=0x7fffffffc7f8, func=0x3e920c8)
at Python/ceval.c:4117
#57 call_function (oparg=, pp_stack=0x7fffffffc7f8) at Python/ceval.c:4042
#58 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#59 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x3bdc1b0, globals=, locals=, args=,
argcount=1, kws=0x43849c0, kwcount=8, defs=0x2a6f1b8, defcount=35, closure=0x0) at Python/ceval.c:3253
#60 0x00007ffff7a73f28 in function_call (func=0x3beaed8, arg=0x11052610, kw=0x10f281a0) at Objects/funcobject.c:526
#61 0x00007ffff7a449a3 in PyObject_Call (func=0x3beaed8, arg=, kw=) at Objects/abstract.c:2529
#62 0x00007ffff7a570cf in instancemethod_call (func=0x3beaed8, arg=0x11052610, kw=0x10f281a0) at Objects/classobject.c:2602
#63 0x00007ffff7a449a3 in PyObject_Call (func=0x55787d0, arg=, kw=) at Objects/abstract.c:2529
#64 0x00007ffff7ab0cc0 in slot_tp_init (self=0x11047a10, args=0x7ffff7fac050, kwds=0x10f281a0) at Objects/typeobject.c:5692
#65 0x00007ffff7aa7858 in type_call (type=, args=0x7ffff7fac050, kwds=0x10f281a0) at Objects/typeobject.c:745
#66 0x00007ffff7a449a3 in PyObject_Call (func=0x3f81ca0, arg=, kw=) at Objects/abstract.c:2529
#67 0x00007ffff7af34cd in do_call (nk=, na=, pp_stack=0x7fffffffcdf8, func=0x3f81ca0) at Python/ceval.c:4239
#68 call_function (oparg=, pp_stack=0x7fffffffcdf8) at Python/ceval.c:4044
#69 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#70 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x33ae0b0, globals=, locals=, args=,
argcount=7, kws=0x4d087f8, kwcount=6, defs=0x3ff2618, defcount=7, closure=0x0) at Python/ceval.c:3253
#71 0x00007ffff7af3d2a in fast_function (nk=, na=7, n=, pp_stack=0x7fffffffcff8, func=0x417c2a8)
at Python/ceval.c:4117
#72 call_function (oparg=, pp_stack=0x7fffffffcff8) at Python/ceval.c:4042
#73 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#74 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x332aab0, globals=, locals=, args=,
argcount=2, kws=0x4a21780, kwcount=5, defs=0x3be2e00, defcount=22, closure=0x0) at Python/ceval.c:3253
#75 0x00007ffff7af3d2a in fast_function (nk=, na=2, n=, pp_stack=0x7fffffffd1f8, func=0x4179f50)
at Python/ceval.c:4117
#76 call_function (oparg=, pp_stack=0x7fffffffd1f8) at Python/ceval.c:4042
#77 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#78 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x43892b0, globals=, locals=, args=,
argcount=2, kws=0x47a71f8, kwcount=0, defs=0x0, defcount=0, closure=0x48dcb48) at Python/ceval.c:3253
#79 0x00007ffff7af3d2a in fast_function (nk=, na=2, n=, pp_stack=0x7fffffffd3f8, func=0x61bca28)
at Python/ceval.c:4117
#80 call_function (oparg=, pp_stack=0x7fffffffd3f8) at Python/ceval.c:4042
#81 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#82 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x4389b30, globals=, locals=, args=,
argcount=1, kws=0x478a250, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#83 0x00007ffff7af3d2a in fast_function (nk=, na=1, n=, pp_stack=0x7fffffffd5f8, func=0x43856e0)
at Python/ceval.c:4117
#84 call_function (oparg=, pp_stack=0x7fffffffd5f8) at Python/ceval.c:4042
#85 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#86 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7ed3eb0, globals=, locals=, args=,
argcount=1, kws=0x785f78, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#87 0x00007ffff7af3d2a in fast_function (nk=, na=1, n=, pp_stack=0x7fffffffd7f8, func=0x44518c0)
at Python/ceval.c:4117
#88 call_function (oparg=, pp_stack=0x7fffffffd7f8) at Python/ceval.c:4042
#89 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#90 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7ec1cb0, globals=, locals=, args=,
argcount=0, kws=0x2cdd3a0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#91 0x00007ffff7af3d2a in fast_function (nk=, na=0, n=, pp_stack=0x7fffffffd9f8, func=0x4451320)
at Python/ceval.c:4117
#92 call_function (oparg=, pp_stack=0x7fffffffd9f8) at Python/ceval.c:4042
#93 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#94 0x00007ffff7af4a7e in fast_function (nk=, na=, n=, pp_stack=0x7fffffffdb48,
func=0x4451a28) at Python/ceval.c:4107
#95 call_function (oparg=, pp_stack=0x7fffffffdb48) at Python/ceval.c:4042
#96 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#97 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7f09b30, globals=, locals=, args=,
argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#98 0x00007ffff7af5c92 in PyEval_EvalCode (co=, globals=, locals=) at Python/ceval.c:667
#99 0x00007ffff7b15880 in run_mod (arena=0x8af350, flags=0x0, locals=0x63e450, globals=0x63e450, filename=, mod=0x6adec0)
at Python/pythonrun.c:1370
#100 PyRun_FileExFlags (fp=0x785db0, filename=, start=, globals=0x63e450, locals=0x63e450, closeit=1,
flags=0x0) at Python/pythonrun.c:1356
#101 0x00007ffff7aec803 in builtin_execfile (self=, args=) at Python/bltinmodule.c:803
#102 0x00007ffff7af4000 in call_function (oparg=, pp_stack=0x7fffffffdec8) at Python/ceval.c:4021
#103 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#104 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7ee21b0, globals=, locals=, args=,
argcount=3, kws=0x804948, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#105 0x00007ffff7af3d2a in fast_function (nk=, na=3, n=, pp_stack=0x7fffffffe0c8, func=0x7a91b8)
at Python/ceval.c:4117
#106 call_function (oparg=, pp_stack=0x7fffffffe0c8) at Python/ceval.c:4042
#107 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#108 0x00007ffff7af4a7e in fast_function (nk=, na=, n=, pp_stack=0x7fffffffe218,
func=0x79d488) at Python/ceval.c:4107
#109 call_function (oparg=, pp_stack=0x7fffffffe218) at Python/ceval.c:4042
#110 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2666
#111 0x00007ffff7af5b7e in PyEval_EvalCodeEx (co=0x7ffff7f017b0, globals=, locals=, args=,
argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253
#112 0x00007ffff7af5c92 in PyEval_EvalCode (co=, globals=, locals=) at Python/ceval.c:667
#113 0x00007ffff7b15880 in run_mod (arena=0x66cdc0, flags=0x7fffffffe510, locals=0x63e450, globals=0x63e450, filename=,
mod=0x6960f0) at Python/pythonrun.c:1370
#114 PyRun_FileExFlags (fp=0x6a7420, filename=, start=, globals=0x63e450, locals=0x63e450, closeit=1,
flags=0x7fffffffe510) at Python/pythonrun.c:1356
#115 0x00007ffff7b15a5f in PyRun_SimpleFileExFlags (fp=0x6a7420, filename=0x7fffffffe881 "/my/python/script",
closeit=1, flags=0x7fffffffe510) at Python/pythonrun.c:948
#116 0x00007ffff7b2b5d4 in Py_Main (argc=, argv=) at Modules/main.c:640
#117 0x00007ffff6ddfd1d in __libc_start_main () from /lib64/libc.so.6
#118 0x0000000000400649 in _start ()


Reply to this email directly or view it on GitHub
#4834 (comment).

@juliantaylor
Copy link
Contributor

thanks for the traceback, it shows that the hook is called from the __dealloc__ method of the geoslib cython bindings.
assuming you are using the numpy provided python hook function this will invoke undefined behaviour as during execution of the python code of the hook the python garbage collector kicks in and tries to delete the object your are currently already deallocating.
I guess to use the hook with cythonized code you will have to write the whole allocation manager in C/Cython and make sure to not call any python API that might trigger access to the object being deleted

possibly you can also get away with just disabling the garbage collector during the python hook (gc.disable/gc.enable)

@njsmith, by quoting the traceback you referenced all PRs 1-118, it seems github is not smart enough to ignore email quotes :)

@njsmith
Copy link
Member

njsmith commented Jul 3, 2014

Doh, sorry :-)

I don't understand the problem. In general it is legal to call arbitrary
python code from finalizers - is this a difference between del and
tp_dealloc or something, with Cython only exposing the latter?
On 3 Jul 2014 14:07, "Julian Taylor" notifications@github.com wrote:

thanks for the traceback, it shows that the hook is called from the
dealloc method of the geoslib cython bindings.
assuming you are using the numpy provided python hook function this will
invoke undefined behaviour as during execution of the python code of the
hook the python garbage collector kicks in and tries to delete the object
your are currently already deallocating.
I guess to use the hook with cythonized code you will have to write the
whole allocation manager in C/Cython and make sure to not call any python
API that might trigger access to the object being deleted

@njsmith https://github.com/njsmith, by quoting the traceback you
referenced all PRs 1-118, it seems github is not smart enough to ignore
email quotes :)


Reply to this email directly or view it on GitHub
#4834 (comment).

@juliantaylor
Copy link
Contributor

__dealloc__ is a special cython method which is restricted in what python stuff you can do, I don't think it maps to tp_dealloc
http://docs.cython.org/src/userguide/special_methods.html#finalization-method-dealloc

@letmaik
Copy link
Author

letmaik commented Jul 3, 2014

Ok, at least the cause of the error is clear now. But I'm afraid that this is a bit too heavy for me, I just wrote some simple Cython wrappers, nothing really complicated with numpy's API or so.

@juliantaylor
Copy link
Contributor

can you try if putting gc.disable() and gc.enable() around the code in the hook function helps?

@letmaik
Copy link
Author

letmaik commented Jul 3, 2014

Your suggestion seems to work. I'll let it run overnight and see if it crashes. Still, I have the feeling that garbage collection could theoretically still happen between the moment of invoking hook and executing the gc.disable() function. Am I wrong?

@njsmith
Copy link
Member

njsmith commented Jul 3, 2014

I would also expect that calling gc.enable() has the potential to trigger
an immediate gc, and if the problem is that running the cycle collector
inside a dealloc function is invalid, then this will not work.

We might want to ask the cython folks if they have any understanding or
suggestions.

On Thu, Jul 3, 2014 at 4:41 PM, Maik Riechert notifications@github.com
wrote:

Your suggestion seems to work. I'll let it run overnight and see if it
crashes. Still, I have the feeling that garbage collection could
theoretically still happen between the moment of invoking hook and
executing the gc.disable() function. Am I wrong?


Reply to this email directly or view it on GitHub
#4834 (comment).

Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org

@juliantaylor
Copy link
Contributor

yes adding the disable in the python code will involve a python function call which can trigger garbage collection so it will only decrease the probability of a crash.
The gc triggers on every x-th memory allocation, gc.enable() does not trigger one with current python versions, gc.collect is used for that.
Unfortunately there seems to be no C-API to disable the collector we could use within the C part of the hook to avoid the window of possibility.

But as long as it works most of the time it should be a fine workaround, the hooks are only for development/debugging anyway.

@njsmith
Copy link
Member

njsmith commented Jul 3, 2014

Fair enough I guess.

Another reason perhaps to look forward to tracemalloc, which IIRC
implements the tracing in pure C :-).

On Thu, Jul 3, 2014 at 5:23 PM, Julian Taylor notifications@github.com
wrote:

yes adding the disable in the python code will involve a python function
call which can trigger garbage collection so it will on decrease the
probability of a crash.
The gc triggers on x-th ever memory allocation, gc.enable() does not
trigger one with current python versions, gc.collect is used for that.
Unfortunately there seems to be no C-API to disable the collector we could
use within the hook to avoid the window of possibility.

But as long as it works most of the time it should be fine workaround, the
hooks are only for development/debugging anyway.


Reply to this email directly or view it on GitHub
#4834 (comment).

Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org

@letmaik
Copy link
Author

letmaik commented Jul 5, 2014

I didn't have any other crashes, so I think this workaround is fine for now and could be integrated.

@juliantaylor
Copy link
Contributor

k, thanks for the feedback

juliantaylor added a commit to juliantaylor/numpy that referenced this issue Jul 5, 2014
When a cython object contains numpy arrays the pure python allocation
hook can trigger during cythons __dealloc__ method and trigger a second
deletion of the object currently being deleted.
To minimize the probabily that that happens disable the garbage
collector during the hook.
As this involves python calls it is still possible that a double delete
occurs but chances are lowered, a proper solution would be C only hook
like python 3.4 tracemalloc module.

Closes numpygh-4834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants