Skip to content

Commit 3647fc2

Browse files
committed
Do not register signal handlers by default anymore
1 parent 2cab261 commit 3647fc2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

docs/config.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ General Settings
3434
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``.
3535
``WSGIWrite``:
3636
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``.
37+
``RegisterSignalHandler``:
38+
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``.
39+
40+
.. _WSGIRestrictSignal: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIRestrictSignal.html
3741

3842
Path Handling
3943
~~~~~~~~~~~~~

webware/Application.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
PlugIns=['MiscUtils', 'WebUtils', 'TaskKit', 'UserKit', 'PSP'],
103103
PrintConfigAtStartUp=True,
104104
PrintPlugIns=True,
105+
RegisterSignalHandler=False,
105106
ReloadServletClasses=False,
106107
ReportRPCExceptionsInWebware=True,
107108
ResponseBufferSize=8 * 1024, # 8 kBytes
@@ -250,11 +251,12 @@ def __init__(self, path=None, settings=None, development=None):
250251

251252
self._needsShutDown = [True]
252253
atexit.register(self.shutDown)
253-
self._sigTerm = signal.signal(signal.SIGTERM, self.sigTerm)
254-
try:
255-
self._sigHup = signal.signal(signal.SIGHUP, self.sigTerm)
256-
except AttributeError:
257-
pass # SIGHUP does not exist on Windows
254+
if self.setting('RegisterSignalHandler'):
255+
self._sigTerm = signal.signal(signal.SIGTERM, self.sigTerm)
256+
try:
257+
self._sigHup = signal.signal(signal.SIGHUP, self.sigTerm)
258+
except AttributeError:
259+
pass # SIGHUP does not exist on Windows
258260

259261
def initErrorPage(self):
260262
"""Initialize the error page related attributes."""

0 commit comments

Comments
 (0)