0

I am reading rows from a sqlite db, looping over them and then using the variables from each row as arguments for a function which generates plots, something like the following pseudo code

conn=sqlite3.connect(db)
c=conn.cursor()
myrows=c.execute("select * from values WHERE var=1")
for burst in myrows:
    met=burst[1]
    make_plot(met)
c.close()    

After a certain amount of time this gives either one of the following errors:

1) 86392 items requested but only 0 read Segmentation fault

2) unable to alloc 3072000 bytes Aborted

3) Segmentation fault

The make_plot() has to read in a large file (~8 mB) and do some operations on the data, and there are ~500 elements in myrows. From the errors I think that I am running out of memory(?) but I haven't managed to find anything that would help me track down/diagnose this problem. Any ideas on how I would do this?

2 Answers 2

1

can't you say something like below, if all you care is this second field?

myrows=c.execute("select values.bust from values WHERE var=1")

also, i am wondering you really want to create plot for each line... dont you want to plot all the data in one plot?

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, Each entry in the database that I am selecting has its own data & its own plot that has to be made. The code I posted is a simplified version which just contains the steps (i.e. I have removed most of the variables). Cheers
so this make_plot() opens a file of ~8MB for every call and process that combining with a record in myrows? Do you know error is coming from my_plot() or from this loop across records in your database? Is there any chance that there is some memory leak in there or illegal access of memory?
It turned out that the version of the pyfits module that I was using (2.4) had a memory leak, I upgraded to 3.0 and it improved the problem, i.e. it ran for longer before using all my ram. It turns out that I was also missing a plt.close(fig) at the end of my plotting function - popped that it and it all worked fine. Cheers
@user1027686: it is always great to hear that things start workin!
0

Try and see if by changing your for statement to:

for burst in c.execute("select * from values WHERE var=1"):
    # your code here

rows aren't retrieved one at a time rather than in a single batch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.