Skip to content

Commit

Permalink
Do not register signal handlers by default anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Dec 19, 2020
1 parent 2cab261 commit 3647fc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ General Settings
Buffer size for the output response stream. This is only used when a servlet has set ``autoFlush`` to True using the ``flush()`` method of the Response. Otherwise, the whole response is buffered and sent in one shot when the servlet is done. Default: ``8192``.
``WSGIWrite``:
If this is set to True, then the write() callable is used instead of passing the response as an iterable, which would be the standard WSGI mechanism. Default: ``True``.
``RegisterSignalHandler``:
When the Application is regularly shut down, it tries to save its Sessions and stop the TaskManager. An atexit-handler will do this automatically. You can also shut down the Application manually by calling its ``shutDown()`` method. If this setting is set to True, then the Application will also register signal handlers to notice when it is shutdown and shut down cleanly. However, as the ``mod_wsgi`` documentation explains (see section on WSGIRestrictSignal_), "a well behaved Python WSGI application should not in general register any signal handlers of its own using ``signal.signal()``. The reason for this is that the web server which is hosting a WSGI application will more than likely register signal handlers of its own. If a WSGI application were to override such signal handlers it could interfere with the operation of the web server, preventing actions such as server shutdown and restart." Therefore, the default setting is: ``False``.

.. _WSGIRestrictSignal: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIRestrictSignal.html

Path Handling
~~~~~~~~~~~~~
Expand Down
12 changes: 7 additions & 5 deletions webware/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
PlugIns=['MiscUtils', 'WebUtils', 'TaskKit', 'UserKit', 'PSP'],
PrintConfigAtStartUp=True,
PrintPlugIns=True,
RegisterSignalHandler=False,
ReloadServletClasses=False,
ReportRPCExceptionsInWebware=True,
ResponseBufferSize=8 * 1024, # 8 kBytes
Expand Down Expand Up @@ -250,11 +251,12 @@ def __init__(self, path=None, settings=None, development=None):

self._needsShutDown = [True]
atexit.register(self.shutDown)
self._sigTerm = signal.signal(signal.SIGTERM, self.sigTerm)
try:
self._sigHup = signal.signal(signal.SIGHUP, self.sigTerm)
except AttributeError:
pass # SIGHUP does not exist on Windows
if self.setting('RegisterSignalHandler'):
self._sigTerm = signal.signal(signal.SIGTERM, self.sigTerm)
try:
self._sigHup = signal.signal(signal.SIGHUP, self.sigTerm)
except AttributeError:
pass # SIGHUP does not exist on Windows

def initErrorPage(self):
"""Initialize the error page related attributes."""
Expand Down

0 comments on commit 3647fc2

Please sign in to comment.