gpt4 book ai didi

python - NameError : name 'hasattr' is not defined - Python3. 6, Django1.11, Ubuntu16-17, Apache2.4, mod_wsgi

转载 作者:太空狗 更新时间:2023-10-29 21:48:33 25 4
gpt4 key购买 nike

我已经在守护进程模式下设置了我的 Python/Django 虚拟环境和 mod_wsgi,并且非常确定(之前做过)它“大部分是正确的”除了我得到以下错误.. .

[Thu Jul 06 00:35:26.986363 2017] [mpm_event:notice] [pid 11442:tid 140557758930432] AH00493: SIGUSR1 received.  Doing graceful restart
Exception ignored in: <object repr() failed>
Traceback (most recent call last):
File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/PIL/Image.py", line 572, in __del__
NameError: name 'hasattr' is not defined
[Thu Jul 06 00:35:27.194483 2017] [mpm_event:notice] [pid 11442:tid 140557758930432] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming normal operations
[Thu Jul 06 00:35:27.194561 2017] [core:notice] [pid 11442:tid 140557758930432] AH00094: Command line: '/usr/sbin/apache2'

我的 django 应用程序本身通过 wsgi.py 加载正常,但它似乎与核心 python 有关(我的设置可能出错)按照以下方式出错:NameError: name 'hasattr' is not defined

在浏览器中 - 我得到一个普通的“服务器错误 (500)”页面,而不是标准的 Apache“内部服务器错误”页面。

省略我的 VirtualHost 和超出这里的步骤是我为自己整理的基本步骤,如果你能发现任何东西......(我已经尝试了所有不同的 python 包,而不仅仅是 -venv)

Install Python 3.6 and virtualenv
sudo apt-get update
sudo apt-get install python3.6-venv
sudo apt-get install virtualenv
(or find the latest and greatest python package that includes pip https://packages.ubuntu.com/ )


Install Apache2
sudo apt-get install apache2 apache2-dev


Make and enter a folder for your project - then build a Virtual Environment in it
mkdir ~/example.com
cd ~/example.com
virtualenv --python=/usr/bin/python3.6 py361ve

Enter your new Virtual Environment to install packages to it
source py361ve/bin/activate

Install Django, mod_wsgi, and any other needed packages
pip install django
pip install mod_wsgi
pip install ...
(no need for pip3 in virtual environment - django should be the latest release)


Run following command and place output in apache config file ( in /etc/apache2/ )
mod_wsgi-express module-config


Exit your virtual environment
deactivate
(You can re-enter your virtual environment any time using the source method in step 8)

这是我停止/启动/重新启动 apache2 时发生的情况...

apache2 stop...

[Thu Jul 06 06:01:34.190940 2017] [mpm_event:notice] [pid 2015:tid 140157449797120] AH00491: caught SIGTERM, shutting down
_______________________________________________________________
apache2 start...

[Thu Jul 06 06:02:39.076741 2017] [mpm_event:notice] [pid 2181:tid 140553545080320] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming $
[Thu Jul 06 06:02:39.076890 2017] [core:notice] [pid 2181:tid 140553545080320] AH00094: Command line: '/usr/sbin/apache2'
_______________________________________________________________
apache2 restart...

Exception ignored in: <object repr() failed>
Traceback (most recent call last):
File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/PIL/Image.py", line 572, in __del__
NameError: name 'hasattr' is not defined
[Thu Jul 06 06:05:43.307877 2017] [mpm_event:notice] [pid 2181:tid 140553545080320] AH00491: caught SIGTERM, shutting down
[Thu Jul 06 06:05:43.492499 2017] [mpm_event:notice] [pid 2301:tid 140353155558912] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming $
[Thu Jul 06 06:05:43.492705 2017] [core:notice] [pid 2301:tid 140353155558912] AH00094: Command line: '/usr/sbin/apache2'

最佳答案

这可能是因为当 Python 解释器在进程关闭时被销毁时代码仍在后台线程中运行。在解释器销毁期间发生的事情是所有模块都被清除,并且事物的属性访问通常返回 None 作为回退。在这种情况下,内置模块似乎在 PIL 对象被销毁之前被删除,因此它找不到 hasattr。

你能确认这只发生在 Apache 重启和进程关闭时吗?

关于python - NameError : name 'hasattr' is not defined - Python3. 6, Django1.11, Ubuntu16-17, Apache2.4, mod_wsgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44939556/

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