Hi, I have a python script that uses a C extention. I keep getting a recurring problem that causes a core dump a few lines after the C extention return data back tp python. I tried using pbd and gdb but I have not succeeded in understanding what went wrong and where. I post the python script here is the error message and gdb output after reading the core file: ..... printout from with C extention.... Completed freeing 2D arrays. Now freeing 1D arrays freed 1D arrays freeing 15km arrays Complete Returning data back to Python! In python: assigning tuple data to numeric arrays! Time to do the coastal effects Segmentation fault (core dumped) ......
Now there next step after "Time to do the coastal effects" was never executed. And even if I put another print statement there the same thing happens. I am using python 2.3 and I have set my stacksize to unlimited. When reading the core dump file with gdb I get: gdb msgppscomp.py core.3203 GNU gdb 6.0-2mdk (Mandrake Linux) Copyright 2003 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i586-mandrake-linux-gnu"..."/data/proj_ns1/safworks/sheldon/msgppscomp.py": not in executable format: File format not recognized Core was generated by `python msgppscomp.py'. Program terminated with signal 11, Segmentation fault. #0 0x40079dfa in ?? () (gdb) ................. I am not very familiar with using gdb with python and C extentions. I would like to get some ideas about where the problem might be. I have made sure that all the arrays in the C extention are freed before exiting so I doubt that this might be the problem. Here is the python script: #!/usr/bin/env python #!-*-coding: UTF-8 -*- class WriteHdfFile: def __init__(self,outfile): self.outfile = outfile self.COMPRESS_LVL = 6 def writeAreainfo(self): import _pyhl import sys sys.float_output_precision = 2 aList = _pyhl.nodelist() aNode = _pyhl.node(_pyhl.GROUP_ID,"/PPS_MSG_COMP") aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/LAT") aNode.setArrayValue(1,lat.shape,lat,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/LON") aNode.setArrayValue(1,lon.shape,lon,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/VALCONCEN") aNode.setArrayValue(1,valconcen.shape,valconcen,"int",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/LIGHTCON") aNode.setArrayValue(1,lightcon.shape,lightcon,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/BIAS100") aNode.setArrayValue(1,bias100.shape,bias100,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/BIAS75") aNode.setArrayValue(1,bias75.shape,bias75,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/BIAS50") aNode.setArrayValue(1,bias50.shape,bias50,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/BIAS25") aNode.setArrayValue(1,bias25.shape,bias25,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/COAST") aNode.setArrayValue(1,coast.shape,coast,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/STATISTICS") aNode.setArrayValue(1,stats.shape,stats,"int",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/PERCENTAGE") aNode.setArrayValue(1,percentage.shape,percentage,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/VA_vs_BIAS") aNode.setArrayValue(1,va_area.shape,va_area,"float",-1) aList.addNode(aNode) aNode=_pyhl.node(_pyhl.DATASET_ID,"/VANUM") aNode.setArrayValue(1,vanum.shape,vanum,"float",-1) aList.addNode(aNode) aNode = _pyhl.node(_pyhl.ATTRIBUTE_ID,"/NSCENES") aNode.setScalarValue(-1,areascenes,"int",-1) aList.addNode(aNode) aNode = _pyhl.node(_pyhl.ATTRIBUTE_ID,"/SATELLITE") aNode.setScalarValue(-1,satid,"string",-1) aList.addNode(aNode) self.status = aList.write(self.outfile,self.COMPRESS_LVL) return self.status #--------------------------------------------------------------------------------------------------------------------------- if __name__ == "__main__": from Numeric import * import sys, os, string, math, glob import msgppsarea,msgppscoast import shelve date = str(200510) #date = sys.argv[1] #s = sys.argv[2] cp = 'cfc' global valconcen,bias100,bias75,lightcon,bias50,bias25,percentage,va_area,lat,lon global stats,areascenes,satid,vanum,coast valconcen = zeros((324,243),'i') bias100 = zeros((324,243),'f') bias75 = zeros((324,243),'f') lightcon = zeros((324,243),'f') bias50 = zeros((324,243),'f') bias25 = zeros((324,243),'f') coast = zeros((324,243),'f') percentage = zeros((60,1),'f') va_area = zeros((90,1),'f') vanum = zeros((90,1),'f') lat = zeros((324,243),'f') lon = zeros((324,243),'f') stats = zeros((60,1), 'i') d = shelve.open("/data/proj/safworks/sheldon/MSG_PPS_COMP/c_codes/"+"_"+date+".shelve") msglist = d["Area.msglist"] tilescenes = d["Area.tilescenes"] tiles = d["Area.tiles"] ppslist = d["Area.ppslist"] lllist = d["Area.lllist"] areascenes = d["Area.areascenes"] d.close() print "Deleting file pointer and calling C function" RES = msgppsarea.msgppsarea(tilescenes,tiles,msglist,ppslist,lllist,int(date),areascenes) print "In python: assigning tuple data to numeric arrays!" for x in range(324): bias100[x] = (RES[0])[x*243:x*243+243] bias75[x] = (RES[1])[x*243:x*243+243] bias50[x] = (RES[2])[x*243:x*243+243] bias25[x] = (RES[3])[x*243:x*243+243] lat[x] = (RES[4])[x*243:x*243+243] lon[x] = (RES[5])[x*243:x*243+243] lightcon[x] = (RES[6])[x*243:x*243+243] valconcen[x] = (RES[7])[x*243:x*243+243] for x in range(90): va_area[x] = (RES[10])[x] vanum[x] = (RES[11])[x] for x in range(60): stats[x] = (RES[8])[x] percentage[x] = (RES[9])[x] print "Time to do the coastal effects" RES = msgppscoast.msgppscoast(ravel(bias100),tiles) for x in range(324): coast[x] = (RES[0])[x*243:x*243+243] outfile = "/data/proj/safworks/sheldon/MSG_PPS_COMP/results/"+'CFC'+'_'+ '_' + date + '.h5' print outfile chk = WriteHdfFile(outfile) res = chk.writeAreainfo() print "File written!" print "Complete!" ******************************** The C extention is very large so I will include it if anyone wants to see it. Thanks for any advice, Sheldon -- http://mail.python.org/mailman/listinfo/python-list