gpt4 book ai didi

Python无法用Supervisor读取环境变量

转载 作者:太空宇宙 更新时间:2023-11-04 09:16:55 25 4
gpt4 key购买 nike

当我运行 sudo -E supervisor reread/reload 时

我在 [program:site] 部分定义了启动 gunicorn.conf.py 的命令

/etc/supervisor/conf.d/weather.conf

[program:site]
directory=/home/nhcc/campus-weather-station/weather_station
command=/home/nhcc/venv/weather_station/bin/gunicorn -c /home/nhcc/campus-weather-station/weather_station/gunicorn.conf.py -p gunicorn.pod weather_station.wsgi

gunicorn.conf.py

# -*- coding: utf-8 -*-
# /usr/bin/python3
import os

bind = "{}:8080".format(os.environ['DJANGO_WEATHER_STATION_HOST'])
worders = (os.sysconf('SC_NPROCESSORS_ONLN') * 2) + 1
loglevel = 'error'
command = "WTR_VENV/gunicorn"
pythonpath = "$PROJECT/weather_station"

它会显示错误。

我在/etc/profile.d/project.sh 中设置了 DJANGO_WEATHER_STATION_HOST

项目.sh

export DJANGO_WEATHER_STATION_HOST=the_host_ip

重新加载后还是没有用。

我也在~/.profile中设置

但还是报错。

File "/home/nhcc/campus-weather-station/weather_station/gunicorn.conf.py", line 5, in bind = "{}:8080".format(os.environ['DJANGO_WEATHER_STATION_HOST']) File "/usr/lib/python3.5/os.py", line 725, in getitem raise KeyError(key) from None KeyError: 'DJANGO_WEATHER_STATION_HOST'

最佳答案

Supervisor维护自己的环境。

在这里阅读更多。 http://supervisord.org/subprocess.html#subprocess-environment

所以你必须在 /etc/supervisor/conf.d/weather.conf 文件中传递环境。

Ex of /etc/supervisor/conf.d/weather.conf 设置了 env

[program:site]
directory=/home/nhcc/campus-weather-station/weather_station
command=/home/nhcc/venv/weather_station/bin/gunicorn -c /home/nhcc/campus-weather-station/weather_station/gunicorn.conf.py -p gunicorn.pod weather_station.wsgi

environment=HOME="/home/chrism",USER="chrism"

关于Python无法用Supervisor读取环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46379828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com