gpt4 book ai didi

python - __name__ 变量等于 "wsgi"而不是 "__main__"

转载 作者:行者123 更新时间:2023-12-01 06:37:02 25 4
gpt4 key购买 nike

我有 wsgi 文件,其中有一行:

wsgi.py

if __name__ == "__main__":
app.run()

但是今天我的服务器没有启动,当我打印 __name__ 时,发现它无缘无故地等于“wsgi”。我像“sudo systemctl restart myserver.service”一样启动我的服务器

myserver.ini

module = wsgi:app

master = true
processes = 3

socket = /var/www/myserver/myserver.sock
chmod-socket = 660
vacuum = true

die-on-term = true
logto = /var/www/myserver/server.log
enable-threads = true

myserver.service

Description=uWSGI instance to serve myserver
After=network.target

[Service]
User=savvasenok
Group=www-data
WorkingDirectory=/var/www/myserver
Environment="PATH=/home/savvasenok/MyServerEnv/bin"
ExecStart=/home/savvasenok/MyServerEnv/bin/uwsgi --ini /var/www/myserver/myserver.ini

[Install]
WantedBy=multi-user.target

最佳答案

正如 here 中所解释的那样:

If the source file is executed as the main program, the interpreter sets the __name__ variable to have a value “__main__”. If this file is being imported from another module, name will be set to the module’s name.

所以原因是您正在运行一个导入 wsgi 的 python 模块(或文件)。在您的情况下,我认为您将 wsgi 导入到 /home/savvasenok/MyServerEnv/bin/uwsgi 模块,您将其作为 ExecStart 并正在运行已执行。

您还可以查看this answer了解更多信息。

关于python - __name__ 变量等于 "wsgi"而不是 "__main__",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59615669/

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