February 16th, 2005, 07:15 PM
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.
data = response.read()
writeobject = open('tmp.txt', 'w')
l = open('sessions.txt', 'a')
print linecache.getline('tmp.txt', 24)
February 17th, 2005, 01:02 AM
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.