Platform:
httpd-2.4.62-1.el9_5.2.x86_64
python3-mod_wsgi-4.7.1-11.el9.x86_64
python3-3.9.21-1.el9_5.x86_64
httpd settings:
WSGIDaemonProcess server.example.com \
processes=2 \
threads=5 \
display-name=%{GROUP} \
shutdown-timeout=100 \
python-path=/custom/python3
WSGIProcessGroup server.exmaple.com
WSGIScriptAlias /test /var/www/cgi-bin/test.wsgi
File /var/www/cgi-bin/test.wsgi
import os,sys,logging
print(sys.path)
print('first')
import foobar
print("second")
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!\n'
response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Execution output in httpd error log:
[wsgi:error] [pid 8260:tid 8405] ['/custom/python3'/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-packages']
[wsgi:error] [pid 8260:tid 8405] first
But it never prints the 'second' line because the import fails - there is no foobar module. But it doesn't output the exception Traceback into error log for some reason. I don't think this is an import related problem per se, but for some reason, the mod_wsgi doesn't output Python tracebacks to the error log at all.
Well, I iterated everything possible and found out that
shutdown-timeout=100
caused it. Now there is a proper strack trace.
[wsgi:error] [pid 22736:tid 22883] [remote 1.1.1.1:52414] mod_wsgi (pid=22736): Failed to exec Python script file '/var/www/cgi-bin/test.wsgi'.
[wsgi:error] [pid 22736:tid 22883] [remote 1.1.1.1:52414] mod_wsgi (pid=22736): Exception occurred processing WSGI script '/var/www/cgi-bin/test.wsgi'.
[wsgi:error] [pid 22736:tid 22883] [remote 1.1.1.1:52414] Traceback (most recent call last):
[wsgi:error] [pid 22736:tid 22883] [remote 1.1.1.1:52414] File "/var/www/cgi-bin/test.wsgi", line 11, in <module>
[wsgi:error] [pid 22736:tid 22883] [remote 1.1.1.1:52414] import foobar
[wsgi:error] [pid 22736:tid 22883] [remote 1.1.1.1:52414] ModuleNotFoundError: No module named 'foobar'
https://modwsgi.readthedocs.io/en/master/configuration-directives/WSGIDaemonProcess.html
shutdown-timeout=sss
Defines the maximum number of seconds allowed to pass when waiting for a daemon process to shutdown. When this timeout has been reached the daemon process will be forced to exited even if there are still active requests or it is still running Python exit functions. The shutdown timeout is applied after any graceful restart timeout or eviction timeout if they have been specified. No new requests are accepted during the shutdown timeout is being applied.
If this option is not defined, then the shutdown timeout will be set to 5 seconds. Note that this option does not change the shutdown timeout applied to daemon processes when Apache itself is being stopped or restarted. That timeout value is defined internally to Apache as 3 seconds and cannot be overridden.
Why it suppresses the traceback, I've no idea.