Disable Apache caching of python files

前端 未结 1 518
盖世英雄少女心
盖世英雄少女心 2020-12-19 23:48

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

相关标签:
1条回答
  • 2020-12-20 00:19

    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.

    0 讨论(0)
提交回复
热议问题