mod_wsgi icon indicating copy to clipboard operation
mod_wsgi copied to clipboard

AttributeError: module 'signal' has no attribute 'SIGHUP'

Open singhal-shagun opened this issue 3 years ago • 2 comments

I am trying to integrate mod_wsgi into my django project on Windows 10. While I was able to install mod_wsgi into my virtual environment, I am running into errors while trying the command 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 seems to suggest that signal.SIGHUP, signal.SIGUSR1 and signal.SIGWINCH as being used by my mod_wsgi installation aren't supported on Windows. So I tried the following two methods in .\venv\Lib\site-packages\mod_wsgi\server\management\commands\runmodwsgi.py:

  1. I tried using the if-condition if platform.system() != 'Linux': as suggested on this Q&A,
  2. I also tried commenting out the lines making use of these signals in this file.

In either case, I kept running across some or the other error, making me wonder if my installation of mod_wsgi is correct at all.

I have been following the instructions as written on mod_wsgi's PyPi listing. I am writing them here for reference:

  1. Obtained a copy of Apache 2.4.54 Win64 from https://www.apachelounge.com/download/
  2. Extracted this zip file and placed the Apache24 folder in my C: as C:\Apache24.
  3. Set Define SRVROOT "c:/Apache24" and Listen 8000 in httpd.conf. Verified that things work and the default homepage is loaded (http://localhost:8000).
  4. Installed Visual Studio C++ build tools using Visual Studio Installer (the 'Desktop development with C++' category).enter image description here
  5. Installed mod_wsgi into my virtual environment by running the command pip install mod-wsgi in my active virtual environment in an x64 Native Tools Command Prompt for VC2022 window.
  6. Added 'mod_wsgi.server', to the list of INSTALLED_APPS in my settings.py.
  7. Ran python manage.py collectstatic
  8. Ran mod_wsgi-express module-config which output the following three lines, which I placed at the end of my 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. Ran python manage.py runmodwsgi, which is resulting in the error log I mentioned at the start of my post.

Please throw light on what I might be doing incorrectly.

I also have Visual Studio installed, which I am using for this project.

I changed from port 80 to port 8000 in httpd.conf because my IIS doesn't allow Apache to run on port 80.

singhal-shagun avatar Dec 12 '22 16:12 singhal-shagun

Sorry for the delay, been overseas on a trip.

On Windows you should do (8) in your list but not (9). That is, don't try and use mod_wsgi-express directly or via Django management command. The mod_wsgi-express functionality is completely experimental and never worked properly on Windows and no one has ever offered to help get it working. It also seems that some changes which where made for Unix systems means it doesn't even run on Windows anymore. That latter issue could be fixed, but not really worth it due to the other issues it had on Windows and no one being willing to help get it working.

So once you do (8), manually configure your Apache installation for hosting your WSGI application and start/stop the Apache service as you would normally.

GrahamDumpleton avatar Dec 21 '22 22:12 GrahamDumpleton

Hi! Thanks for the answer, Graham! For others, what Graham is saying is demonstrated in Johnnyboycurtis's video here. I also created (and answered) a StackOverflow Q&A to this effect.

singhal-shagun avatar Dec 22 '22 05:12 singhal-shagun