last day (15 days later) » 

7:08 PM
0
Q: django server code not updating

Ryan SaxeI have an extensive program that is running on my server. The line with the error looks like the following: result[0].update(dictionary) result[0] looks like ("label",{key:value,...}) so I got an error saying that a tuple does not have update when I fixed it to be result[0][1].update(dictiona...

 
Assuming Python 2, what does print type(result[0]) return?
 
I tried that. I don't get a result because it is running the older version of the program and therefor any edits are not run
 
Have you tried deleting all of the .pyc files, if any?
 
I have never done that before. Note that this is inside a function in a Manager in models.py...would deleting models.pyc be problematic?
 
.pyc files are just the byte-code compiled Python files of the same name. On rare occasion, these files won't get regenerated at runtime when a Python file changes. The models.pyc file will be re-generated as soon as your code is run. It's perfectly fine to delete it.
 
7:08 PM
I just deleted it and reran with the edited code and it still executed the original version
 
Hello
 
Hi
 
Have you tried deleting the file on the remote server completely and replacing it?
I'm sure you have, just want to double-check
 
yeah I have
 
Also, how are you running your Python code on the remote server? Apache/mod_wsgi? Gunicorn?
Regardless of technology, you have to bounce those processes when Python code changes or it won't be reloaded.
 
7:13 PM
I am not sure what the remote server is as my boss is in a different timezone and unavailable at the moment. But on the server I use runserver, which should use wsgi. And the code gets executed through a task manager on the background db. The task is created through a view
I have restarted the django server
but I have not logged out and logged back into the remote server. Is that what you are suggesting?
 
Are you using Celery for the tasks?
If so, have you restarted the Celery workers?
 
no, just background_task. Celery was used originally but we found it to be overkill
background_task doesn't use workers
 
Hmm
 
the task is running
the task calls a function from a manager on an instance of a model
that function will not update for some odd reason
 
that is very strange. Is the object being cached my change?
 
7:15 PM
the weird thing is that when I get my error, it gives me the original error and then the original line number, but the code on the line is from the edited version
I don't believe the object is being cached
but even if it is, I am editing a function of a manager, which would change on a cached object
 
That's extremely odd. Which is why I suggested deleting all of the pyc files. Have you tried renaming the file, then restarting the server and seeing if it still works? If it does, there has to be another copy of whatever file is being accessed somewhere.
 
I cannot rename the file as it is the models.py file
 
I mean just change it to ~models.py and see if it blows up
 
okay, but then when I try and import proj.models in the view I will get an error
so I am not sure if that will be productive
 
my rationale was that if you're changing that file, but it's not picking up the changes, perhaps the wrong models.py was being imported, which is sometimes hard to notice with relative imports. I'm just throwing out as many scenarios as I can think of
 
7:21 PM
Yeah, at this point there is just one weird thing off. I am hesitant to change the name of models.py as there are multiple things running right now that don't need to access this manager so are still running properly. If I change the name, they could break
But I did just check the view and it is accessing the correct file
 
hmm
 
I specify the project that models.py is importing from
 
ah
 
see right now this is my error
...traceback stuff
File "/.../.../models.py", line 127, in predict
print response
AttributeError: 'tuple' object has no attribute 'update'
response[0][1].update(dictionary) was originally on line 27
I only believe it is running the wrong version, but I cannot find the old version
 
can you paste the relevant lines of the manager code?
 
7:24 PM
could anything else be causing this. Since the old version is not stored on the server now that the models.pyc file is gone
 
not that I can think of
that .pyc should get recompiled at runtime.
if it's not being recompiled, it's not being accessed
 
here is the original code
dictionary = function_call(tag_name) #makes dictionary
if len(prev) > 0:
response[0].update(dictionary) #line 127
print response[0]
return (response[0],dictionary.items()[0][0])
here is the edited code
dictionary = function_call(tag_name) #makes dictionary
if len(prev) > 0:
print response #line 127
response[0][1].update(dictionary)
print response[0][1]
return (response[0],dictionary.items()[0][0])
line 127 causes the error
although if another error were to be called in the edited version it would be 128, but that isn't what happens
 
man that is too weird.
I haven't encountered that with a Python file
 
it has happened to me before maybe once. But I never really solved it. I just moved on since it wasn't important and it eventually stopped happening if I recall correctly
this is supposed to be running overnight tonight, so I need to get it working. Thanks for the help. I'll let you know if I find a solution
 
I'm thinking there's something not getting cleaned up by garbage collection that is lingering in memory that's causing the problem, or something else memory related. Since you've replaced the file, deleted the .pyc and restarted the server/workers, it's really hard to tell what could possibly be going on.
 
7:34 PM
Yeah it's hard to tell. How would I tell if it's lingering in memory?
 
I'm not 100% certain. Could be hanging out in memcached or as part of a zombie process.
 
I'll take a look thanks
 
Best of luck. Sorry I wasn't more help
 
you helped eliminate a lot of possibilities. Thanks for everything and have a good one
 
you're welcome. Let me know what you find out!
 

last day (15 days later) »