【问题标题】:AttributeError: module 'signal' has no attribute 'SIGHUP'AttributeError: 模块 \'signal\' 没有属性 \'SIGHUP\'
【发布时间】:2022-12-15 14:17:55
【问题描述】:

我正在尝试将 mod_wsgi 集成到我在 Windows 10 上的 django 项目中。虽然我能够将 mod_wsgi 安装到我的虚拟环境中,但我在尝试命令 python manage.py runmodwsgi 时遇到错误。

(venv) PS D:\Tutorials\Python\Projects\ADSS> python manage.py runmodwsgi
Successfully ran command.
Server URL         : http://localhost:8000/
Server Root        : C:/Users/admin/AppData/Local/Temp/mod_wsgi-localhost-8000-admin
Server Conf        : C:/Users/admin/AppData/Local/Temp/mod_wsgi-localhost-8000-admin/httpd.conf
Error Log File     : C:/Users/admin/AppData/Local/Temp/mod_wsgi-localhost-8000-admin/error_log (warn)
Operating Mode     : daemon
Request Capacity   : 5 (1 process * 5 threads)
Request Timeout    : 60 (seconds)
Startup Timeout    : 15 (seconds)
Queue Backlog      : 100 (connections)
Queue Timeout      : 45 (seconds)
Server Capacity    : 20 (event/worker), 20 (prefork)
Server Backlog     : 500 (connections)
Locale Setting     : en_US.cp1252
Traceback (most recent call last):
  File "D:\Tutorials\Python\Projects\ADSS\manage.py", line 25, in <module>
    execute_from_command_line(sys.argv)
  File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\django\core\management\__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\django\core\management\base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\django\core\management\base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "D:\Tutorials\Python\Projects\ADSS\venv\lib\site-packages\mod_wsgi\server\management\commands\runmodwsgi.py", line 162, in handle
    signal.signal(signal.SIGHUP, handler)
AttributeError: module 'signal' has no attribute 'SIGHUP'

Google 似乎建议我的 mod_wsgi 安装使用的 signal.SIGHUPsignal.SIGUSR1signal.SIGWINCH 在 Windows 上不受支持。于是在.\venv\Lib\site-packages\mod_wsgi\server\management\commands\runmodwsgi.py尝试了以下两种方法:

  1. 我尝试按照this Q&A 上的建议使用 if-condition if platform.system() != 'Linux':
  2. 我还尝试注释掉此文件中使用这些信号的行。

    在任何一种情况下,我都会遇到一些或其他错误,这让我想知道我的 mod_wsgi 安装是否完全正确。

    我一直在按照mod_wsgi's PyPi listing 上的说明进行操作。我写在这里以供参考:

    1. https://www.apachelounge.com/download/ 获得了 Apache 2.4.54 Win64 的副本@
    2. 解压缩此 zip 文件并将 Apache24 文件夹放在我的 C: 中,作为 C:\Apache24
    3. httpd.conf中设置Define SRVROOT "c:/Apache24"Listen 8000。验证一切正常并加载默认主页 (http://localhost:8000)。
    4. 使用 Visual Studio 安装程序(“使用 C++ 的桌面开发”类别)安装了 Visual Studio C++ 构建工具。
    5. 通过在我的活动虚拟环境中的x64 Native Tools Command Prompt for VC2022 窗口中运行命令pip install mod-wsgi,将 mod_wsgi 安装到我的虚拟环境中。
    6. 'mod_wsgi.server', 添加到我的settings.py 中的INSTALLED_APPS 列表中。
    7. python manage.py collectstatic
    8. 运行 mod_wsgi-express module-config 输出以下三行,我将其放在 httpd.conf 的末尾:
      LoadFile "C:/Program Files/Python310/python310.dll"
      LoadModule wsgi_module "D:/Tutorials/Python/Projects/ADSS/venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
      WSGIPythonHome "D:/Tutorials/Python/Projects/ADSS/venv"
      
      1. 运行python manage.py runmodwsgi,这导致了我在文章开头提到的错误日志。

      请阐明我可能做错了什么。

      我还安装了 Visual Studio,我正在将其用于此项目。

      我在httpd.conf 中将端口 80 更改为端口 8000,因为我的 IIS 不允许 Apache 在端口 80 上运行。

【问题讨论】:

    标签: django mod-wsgi


    【解决方案1】:

    好的。所以我找到了一个可行的解决方法。 我没有依赖由命令 python manage.py runmodwsgi 触发的 mod_wsgi 内置管理脚本,而是按照 his video here 中解释的 Johnnyboycurtis 的方法。

    Johnnyboycurtis 在 Windows 环境中的 Apache 上部署 django 应用程序的方法开箱即用。但是,apache 不提供静态文件,即使我按照 django 文档 here 中的说明进行操作。

    因此,为了提供静态文件,我安装了 WhiteNoise。现在,事情似乎运作良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-14
      • 2019-02-18
      • 1970-01-01
      • 2020-01-01
      • 2019-07-20
      • 2021-11-05
      • 2021-11-04
      相关资源
      最近更新 更多