禁用Apache缓存的python文件

编程入门 行业动态 更新时间:2024-10-22 05:12:37
本文介绍了禁用Apache缓存的python文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在和django一起工作,做Facebook集成,需要一个测试服务器。我有很多Apache的问题及其缓存的.pyc文件,我甚至在这里询问stackoverflow 。

该解决方案可行,但我想知道是否有一个禁用此类文件的Apache缓存的选项。服务器重新启动可能是我的问题。

编辑:

这是django.wsgi代码: / p>

path ='/ not / actual / path'如果路径不在sys.path中: sys .path.append(path) os.environ ['DJANGO_SETTINGS_MODULE'] ='notactualproj.settings' import django.core.handlers.wsgi 应用程序= django.core.handlers.wsgi.WSGIHandler()

解决方案

如何解决您的字节码问题

您应该知道为什么不需要的 .pyc 文件在那里首先(这些在你的存储库中?它们应该被忽略)。

在评论中提到,如果您有悬挂 .pyc 导致问题的文件,则可以将所有当您将较新的代码部署到服务器时,您可以将 .pyc 文件作为您的拉取过程的一部分。运行应用程序将重新创建导入模块时所需的应用程序。

现在,如果你真的不想生成字节码,可以使用 PYTHONDONTWRITEBYTECODE 环境变量,但我不会'

如何解决Apache似乎拉老版本的代码。

  • 由python生成的旧字节码文件(例如 .pyc 文件),这可能会导致在特定情况下出现问题,例如用模块替换文件,但不常引起关注。
  • Mod WSGI不会重新加载上传的较新代码。这取决于您正在运行Mod WSGi的模式,通常的症状是,打开页面似乎随机拉取较旧版本的代码。

要解决第一个问题,您只需删除未使用的字节码文件。但是,再次,这可能不是导致你的问题的原因。

为了解决第二个问题,你有两个解决方案

  • 上传较新的代码时,重新启动apache。使用 apache2ctl -k graceful ,这对你的用户来说是透明的,我看不出为什么服务器重新启动可能是一个问题,除非你在共享主机。
  • 使用代码重新加载,您可能需要看看 mod_wsgi 文档。

我不认为字节码是您的问题,代码重新加载可能是。

I'm working with django and doing facebook integration for which is needed a test server. I've had lots of problems with Apache and its caching of .pyc files, I even asked here on stackoverflow.

That solution works but I want to know if there is an option for disabling Apache caching of such files. Server restart might be a problem for me.

EDIT:

Here is the django.wsgi code:

path = '/not/actual/path' if path not in sys.path: sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = 'notactualproj.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()

解决方案

How to solve your "Bytecode problem"

You should probably figure out why those unwanted .pyc files are there in the first place (are these in your repository? They should be ignored).

As mentionned in the comments, if you have dangling .pyc files that cause issues, you could incorporate removing all the .pyc files as part of your pull process when you deploy newer code to the server. Running the app will re-create the ones that are needed when the modules are imported.

Now, if you really don't want to have bytecode generated, you could use the PYTHONDONTWRITEBYTECODE environment variable, but I wouldn't recommend that as it seems a pretty excessive solution.

How to solve Apache seemingly pulling older versions of the code.

Now, you have to make the difference between two problems at play here.

  • Older Bytecode files generated by python (e.g. .pyc files), which can cause an issue in specific cases like replacing a file with a module, but are not often a cause for concern.
  • Mod WSGI not reloading newer code that gets uploaded. This depends on which mode you're running Mod WSGi in, and an usual symptom is that hitting a page seems to randomly pull the newer or older version of the code.

To solve the first issue, you just have to remove unused bytecode files. But, again, this probably isn't what's causing your issue.

To solve the second issue, you have two solutions

  • Restarting apache when you upload newer code. Using apache2ctl -k graceful, this will be transparent to your users, and I can't see why "Server restart might be a problem", unless you're on shared hosting.
  • Using code reloading, you might want to have a look at the mod_wsgi documentation.

I don't think bytecode is your issue, and code reloading probably is.

更多推荐

禁用Apache缓存的python文件

本文发布于:2023-11-01 01:30:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   文件   Apache   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!