0

I'm runing into Memory Error Using python 2.6, pyodbc

The code loops through several Sql statements. Singleton run Ok, but the loops get stuck. Sometimes Loop works ok.

for Sql in LoopList:
     f = csr.execute(Sql)
     LL = list(f) 

The second element in loop crashes.

Sql:

Sql   =""" SELECT * FROM group WHERE 
        C>10 AND M <0 AND S<0  
        AND TC >= 200 AND OC >=1000  and Penny =.01 
        ORDER BY MSlp           
"""
10
  • 1
    LL crashes? what do you mean? Commented Jul 28, 2011 at 16:14
  • How much data is returned by the SQL statement? If it's hundreds of megabytes or larger, that's your problem right there. Commented Jul 28, 2011 at 16:15
  • It would be helpful if you added a stack trace from the crash, told which platform you're running, what database you are using and other details that may help people identify or recognize the problem. The code you have is really so simple that I doubt it is simply a pyodbc error. Commented Jul 28, 2011 at 16:16
  • @joaguin, its hangs... or stops running error console Memory error. Commented Jul 28, 2011 at 16:16
  • how large is the result set? maybe too large for python to cope with? Commented Jul 28, 2011 at 16:17

3 Answers 3

4

Your query is returning too much data to fit into memory. The execute is probably returning an iterator which only needs to keep one item in memory at a time, but converting that into a list requires every single item returned from the query to fit into memory.

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

Comments

0

The solution was to do sql looplist inside MySQL as Stored procedure, call from python. This eliminated the python error.

also use numpy for testing bytesize

Comments

0

Since your query is returning too much data that it cannot be stored in RAM, for a quick solution try increasing your virtual memory.

  1. Open My Computer
  2. Right click and select Properties
  3. Go to Advanced System Settings
  4. Click on Advance Tab
  5. Click on settings under Performance
  6. Click on Change under Advance Tab
  7. Increase the memory size, that will increase virtual memory size.

It will convert some of your hard disk space to virtual memory, and your issue will be resolved now if your data fits into allocated memory.

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.