#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    3
    Rep Power
    0

    variable not being reset (garbage collection problem?)


    It's a rather long bit of code so I don't want to post it if it's not necessary. Here's what's going on:

    Make a connection to a web server and write the return data to tmp.txt. Copy line 24 from tmp.txt and append to session.txt. Close the http connection. Close each open file. Loop through while for a bit.

    The problem is that the value appended to session.txt is always the same value. Even though tmp.txt is being re-written with new data each iteration through the while loop (evidenced in the print statements and the fact that tmp.txt is actually changing).

    If I call the script from an external source (loop the calling of the script from a while loop in bash) everything is fine. The session.txt file is appended with new data each iteration through the loop.

    These should be the two offending pieces of code. They are both within their own functions but part of the same .py file.

    PHP Code:
    ....snip....
        
    data response.read()
        
    writeobject open('tmp.txt''w')
        
    writeobject.write(data)
        
    writeobject.close()
        
    h.close() 
    PHP Code:
    def writefile():
        
    open('sessions.txt''a')
        
    l.write(linecache.getline('tmp.txt'24))
        print 
    linecache.getline('tmp.txt'24)
        
    l.close() 
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    16
    If you are using linecache, be sure to update the cache by calling the checkcache() function if the file has been modified. For details see the linecache module documentation.

IMN logo majestic logo threadwatch logo seochat tools logo