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

前端 未结 3 1359
猫巷女王i
猫巷女王i 2021-01-12 10:54

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 fol

相关标签:
3条回答
  • 2021-01-12 11:06

    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.

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

    0 讨论(0)
  • 2021-01-12 11:09

    I encountered the same problem as well.

    [Wed Sep 12 16:30:19 2018] [notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/4.6.4     
    Python/3.6 configured -- resuming normal operations
    Exception ignored in: <object repr() failed>
    Traceback (most recent call last):
      File "/mnt/workshop/py36env/lib/python3.6/site-packages/PIL/Image.py", line 600, in __del__
    NameError: name 'hasattr' is not defined
    Exception ignored in: <object repr() failed>
    Traceback (most recent call last):
      File "/mnt/workshop/py36env/lib/python3.6/site-packages/PIL/Image.py", line 600, in __del__
    NameError: name 'hasattr' is not defined
    Exception ignored in: <object repr() failed>
    Traceback (most recent call last):
      File "/mnt/workshop/py36env/lib/python3.6/site-packages/PIL/Image.py", line 600, in __del__
    NameError: name 'hasattr' is not defined
    Exception ignored in: <object repr() failed>
    Traceback (most recent call last):
      File "/mnt/workshop/py36env/lib/python3.6/site-packages/PIL/Image.py", line 600, in __del__
    NameError: name 'hasattr' is not defined
    Exception ignored in: <object repr() failed>
    Traceback (most recent call last):
      File "/mnt/workshop/py36env/lib/python3.6/site-packages/PIL/Image.py", line 600, in __del__
    NameError: name 'hasattr' is not defined
    [Wed Sep 12 16:33:57 2018] [notice] caught SIGTERM, shutting down
    [Wed Sep 12 16:33:58 2018] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
    

    It maybe happened when you made a new dir but never authorized.

    And I fixed it by the following:

    chmod -R 755 /mnt/workshop/your_project_path
    chown -R apache:apache /mnt/workshop/your_project_path
    
    0 讨论(0)
  • 2021-01-12 11:28

    Try uninstalling PIL completely, and then reinstall Pillow package.

    Actually there is conflict in PIL old package and Pillow package which is in conflict with newer versions of django.

    You need to install the new Pillow package.

    First Uninstall both

    sudo pip3 uninstall pil
    sudo pip3 uninstall pillow
    

    Reinstall Pillow

    sudo pip3 install pillow
    
    0 讨论(0)
提交回复
热议问题