pycache怎么用_python - Python3.8-获取适用于Python3.8 Web应用程序的新功能PYTHONPYCACHEPREFIX - 堆栈内存溢出...

Python3.8引入了PYTHONPYCACHEPREFIX环境变量,允许pycache使用独立的缓存目录。尽管可以通过命令行与Python3.8配合使用,但在WSGI Web应用程序中应用此变量时遇到问题。本文探讨如何在WSGI配置(如Apache mod_wsgi)中正确设置该变量,以确保Web应用能够利用这一新功能。
摘要由CSDN通过智能技术生成

Python3.8具有一项新功能,您可以将PYTHONPYCACHEPREFIX环境变量设置为dir路径,以便pycache使用单独的并行文件系统树,而不是每个源目录中的默认__pycache__子目录:

我设置了这个环境变量:

export PYTHONPYCACHEPREFIX="$HOME/.cache/pycache/"

它可以直接通过命令行与python3.8协同工作,但不适用于python3.8 WSGI Web应用程序。 您如何通过WSGI Web应用程序使用它? 这是我的WSGI Web应用程序的示例:

# apache.conf Load python3.8 mod_wsgi (installed mod_wsgi by Python3.8 pip)

LoadModule wsgi_module /path/to/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so

# Vhost

ServerName example1.example.com

# The Python-home runs Python3.8 in venv

WSGIDaemonProcess example1 processes=2 threads=15 display-name=%{GROUP} python-home=/home/ubuntu/web-apps/example1/venv

WSGIProcessGroup example1

WSGIScriptAlias / /home/ubuntu/web-apps/example1/web/app.wsgi

Options -Indexes +FollowSymLinks

Require all granted

# example1/web/app.wsgi

import os

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))

from web.app import application

# example1/web/app.py

# Will return "Hello. Python version is 3.8.0"

import sys

def application(environ, start_response):

status = '200 OK'

header = [('Content-type', 'text/html; charset=utf-8')]

content = f"Hello. Python version is {sys.version}"

start_response(status, header)

content = content.encode('utf-8')

return [content]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值