NameError:未定义名称"hasattr"-Python3.6,Django1.11,Ubuntu16-17,Apache2.4,mod_wsgi [英] NameError: name 'hasattr' is not defined - Python3.6, Django1.11, Ubuntu16-17, Apache2.4, mod_wsgi

查看:98
本文介绍了NameError:未定义名称"hasattr"-Python3.6,Django1.11,Ubuntu16-17,Apache2.4,mod_wsgi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在守护程序模式下设置了我的Python/Django虚拟环境和mod_wsgi,并且可以肯定(之前做过)它"大致正确",除了出现以下错误.

I've set up my Python/Django virtual environment, and mod_wsgi in daemon mode, and am pretty sure (done this before) it's "mostly correct" except I get the following error...

[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

My django app itself is loading fine through wsgi.py but it seems something to do with core python (error with my setup likely) is going wrong as per: NameError: name 'hasattr' is not defined

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

In the browser - I get a plain "Server Error (500)" page and not the standard Apache "Internal Server Error" page.

如果您能发现任何东西,请忽略我的VirtualHost和其他步骤,这是我为自己准备的基本步骤...(我尝试了所有不同的python软件包,而不仅仅是-venv)

Leaving out my VirtualHost and steps beyond here are the basic steps I put together for myself if you can spot anything... (I've tried all the different python packages as well not just -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时发生的事情...

Here's what happens when I stop/start/restart 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对象之前已擦除了buildins模块,因此找不到hasattr.

This is likely due to code still running in background threads when the Python interpreter is being destroyed on process shutdown. What happens during interpreter destruction is that all modules get wiped out and attribute access of things often returns None as fallback. In this case looks like builtins module was wiped before the PIL object got destroyed and so it couldn't find hasattr.

您能确认仅在重新启动Apache并关闭进程时会发生这种情况吗?

Can you confirm this only happens when Apache is being restarted and processes shutdown?

这篇关于NameError:未定义名称"hasattr"-Python3.6,Django1.11,Ubuntu16-17,Apache2.4,mod_wsgi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆