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

Memory leak when pulling more records than itersize #32

Open
d33tah opened this issue Apr 17, 2015 · 0 comments
Open

Memory leak when pulling more records than itersize #32

d33tah opened this issue Apr 17, 2015 · 0 comments

Comments

@d33tah
Copy link

d33tah commented Apr 17, 2015

Here's how I called a query:

    cursor = connection.cursor()                                                   
    sql = """                                                                      
    SELECT  "wikispy_edit"."id",                                                   
            "wikispy_edit"."wikipedia_edit_id",                                    
            "wikispy_edit"."title",                                                
            "wikispy_edit"."ip",                                                   
            "wikispy_edit"."wiki_id",                                              
            "wikispy_rdns"."rdns",                                                 
            "wikispy_wiki"."language",                                             
            "wikispy_wiki"."domain"                                                
    FROM "wikispy_edit"                                                            
    INNER JOIN "wikispy_rdns"                                                      
        ON ( "wikispy_edit"."ip" = "wikispy_rdns"."ip" )                           
    INNER JOIN "wikispy_wiki"                                                      
        ON ( "wikispy_edit"."wiki_id" = "wikispy_wiki"."id" )                      
    WHERE                                                                          
            REVERSE("wikispy_rdns"."rdns") LIKE REVERSE(%s)                        
        AND                                                                        
            "wikispy_wiki"."name" = %s                                             
    LIMIT 2001                                                                     
    """                                                                            
    params = ['%' + rdns, wikiname]                                                
    #if sql_scans_table(sql, "wikispy_edit", params):                              
    #    raise RuntimeError("The query is too big.")                               
    # http://stackoverflow.com/a/2679222/1091116                                   
    cursor.execute(sql, params)                                                    
    description = [x[0] for x in cursor.description]                               
    for row in cursor:                                                             
        yielded = dict(zip(description, row))                                      
        yield yielded                                                              

If this gives more than 2000 rows, which is itersize defined in psycopg2ct/_impl/cursor.py, the Python process eats all the memory possible and probably goes into some infinite loop. Raising works as a workaround.

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

No branches or pull requests

1 participant