django服务器代码未更新 [英] django server code not updating

查看:53
本文介绍了django服务器代码未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上正在运行一个扩展程序.出现错误的行如下所示:

I have an extensive program that is running on my server. The line with the error looks like the following:

result[0].update(dictionary)

结果[0] 看起来像("label",{key:value,...}),所以我收到一条错误消息,说一个 tuple没有 update

result[0] looks like ("label",{key:value,...}) so I got an error saying that a tuple does not have update

当我将其修复为 result [0] [1] .update(dictionary)时,我遇到了同样的错误!

when I fixed it to be result[0][1].update(dictionary), I got the same error!

然后我在上面添加了 print"test" 来查看发生了什么,并且得到了相同的错误,但是它给了我在print语句中发生的错误.这告诉我服务器正在运行的代码是原始代码,而不是已编辑的代码.我尝试重新启动服务器.我已经保存了我的代码.我不明白为什么也不发生这种情况.是什么引起的,如何使服务器识别较新的版本?

I then added print "test" above to see what happened, and I got the same error, but it gave me the error occurring at the print statement. This tells me that the code the server is running is the original and not the edited one. I tried restarting the server. I have saved my code. I do not understand why nor how this is happening. What could be causing this and how can I make it so that the server recognizes the newer version?

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/background_task/tasks.py", line 160, in run_task
    tasks.run_task(task.task_name, args, kwargs)                                                                                                      [2/1832]
  File "/usr/local/lib/python2.7/dist-packages/background_task/tasks.py", line 45, in run_task
    task.task_function(*args, **kwargs)
  File "/.../proj/tasks.py", line 10, in automap_predict
    automap_obj.predict()
  File "/.../proj/models.py", line 317, in predict
    prediction = predictions[1]
  File "/.../proj/models.py", line 143, in predict
    #this is a recursive call
  File "/.../proj/models.py", line 143, in predict
    #this is a recursive call
  File "/.../proj/models.py", line 127, in predict
    #result[0].update(dictionary) this happens at the base case of the recursion
AttributeError: 'tuple' object has no attribute 'update'

请注意,我在被注释掉的行上收到此错误.显示这不是真正在运行的代码.

notice that I am getting this error on a line that is commented out. Displaying that this is not the code that is really running.

def view(request,param):
    run_background_task(param)
    return redirect("project.view.reload")

background_task

@background(schedule=0)
def run_background_task(param):
    obj = MyModel.objects.get(field=param)
    obj.predict()

预测功能

这是创建结果的地方.我不允许显示此代码,但是请注意,我确定实际的代码是不相关的.它正在工作.我将其更改为快速更新.我有一个错误.然后,我修复了该错误,但继续得到相同的错误.我什至回到了可以正常工作的旧版本,但仍然遇到相同的错误.因此,此错误与此函数的内容无关.

predict function

This is where the result gets created. I am not permitted to show this code, but note that I am sure that the actual code is irrelevant. It was working. I changed it to make a quick update. I got an error. I then fixed the error, but proceeded to get the same error. I even went back to the old version that was working and I still get the same error. Therefor this error has nothing to do with the contents of this function.

让我知道我是否还能再提供帮助.

Let me know if I can be of any more help.

推荐答案

如果您正在运行django提供的开发服务器,即 ./manage.py runserver ,则不应遇到此问题,因为保存.py文件时,它会自动重新编译.但是,如果您正在运行wsgi,请说使用apache服务器是一个普遍的问题,但是有一个非常简单的解决方案.基本上会发生什么,只要您更改.py文件,服务器仍将使用以前编译的python文件.因此,解决方案是重启apache sudo服务apache2 restart (这是一个过大的杀伤力),或者只是运行 touch wsgi.py (无论您的wsgi.py位于项目中的哪个位置),会告诉它重新编译.py文件.当然,您也可以删除.pyc文件,但这太繁琐了.

If you are running a development server provided with django, namely ./manage.py runserver you should not experience this problem, since it automatically recompiles upon .py file saving. But if you are running wsgi say with apache server it is a common issue, but with a very simple solution. Basically what happens, whenever you change a .py file, server will still use a previously compiled python file. So solution is either restart apache sudo service apache2 restart (which is an overkill) or simply run touch wsgi.py, wherever your wsgi.py is located within a project, which will tell it to recompile .py files. Of course you can also delete the .pyc files, but that is too tedious.

我只是注意到您正在使用 @background 装饰器,这使我相信您正在使用django-background-task .在这种情况下,您将必须确保该应用程序确实也考虑了代码更改,在使用 touch wsgi.py 方法重新编译python文件时,这可能不会自动发生.我没有使用此特定应用程序的经验,但例如使用 celery 的经验还多复杂的应用程序来安排任务,您还必须重新启动工作程序以反映代码中的更改,因为工作程序实际上存储的是代码的腌制版本.

I just notice that you are using @background decorator, which make me believe you are using django-background-task. If that's the case, you will have to make sure this app actually takes your code changes into account too, which may not happen automatically while recompiling python files using touch wsgi.py approach. I don't have experience with this particular app, but for example with celery, which is a lot more sophisticated app for scheduling tasks, you would also have to restart the worker in order to reflect the changes in code, since worker actually stores a pickled version of the code.

现在,在检查出 django-background-task 应用程序(似乎是您正在使用的应用程序)之后,从理论上讲,您不必做任何特殊的事情,而只是确保您可以清除所有计划的任务并重新计划它们.我没有尝试过,但您应该可以通过 ./manage.py shell :

Now after checking out the django-background-task app (which seems like the one you are using), in theory you should't have to do anything special, but just to make sure you can clear out any scheduled tasks and reschedule them again. I haven't tried but you should be able to do it through ./manage.py shell:

>>> from background_task.tasks import tasks
>>> tasks._tasks = {}

也许您甚至必须为 DBTaskRunner 清除数据库:

And probably you'll even have to clear out the db, for the DBTaskRunner:

>>> from background_task.models import Task
>>> Task.objects.all().delete()

这篇关于django服务器代码未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆