Author: chrisz
Date: Sat Dec 8 04:08:03 2007
New Revision: 7117
Modified:
Webware/trunk/WebKit/Admin/Sleep.py
Webware/trunk/WebKit/Application.py
Webware/trunk/WebKit/Docs/Configuration.txt
Webware/trunk/WebKit/ThreadedAppServer.py
Log:
Differentiate the thread cancelation exceptions.
Modified: Webware/trunk/WebKit/Admin/Sleep.py
==============================================================================
--- Webware/trunk/WebKit/Admin/Sleep.py (original)
+++ Webware/trunk/WebKit/Admin/Sleep.py Sat Dec 8 04:08:03 2007
@@ -1,7 +1,7 @@
import os
from time import sleep
-from WebKit.Application import ConnectionAbortedError
+from WebKit.ThreadedAppServer import ThreadAbortedError
from AdminSecurity import AdminSecurity
@@ -35,9 +35,9 @@
sleep(0.125)
count += 1
wr('<p>Time over, woke up!</p>')
- except ConnectionAbortedError:
+ except ThreadAbortedError, e:
duration = int((count+4)/8)
- wr('<p style="color:red">Sleep aborted after %d seconds!</p>'
- % duration)
+ wr('<p style="color:red">Sleep aborted with %s after %d seconds!</p>'
+ % (e.__class__.__name__, duration))
wr('<p>Request %d has been processed.</p>'
% self.request().requestID())
Modified: Webware/trunk/WebKit/Application.py
==============================================================================
--- Webware/trunk/WebKit/Application.py (original)
+++ Webware/trunk/WebKit/Application.py Sat Dec 8 04:08:03 2007
@@ -650,7 +650,7 @@
self.runTransactionViaServlet(servlet, trans)
except EndResponse:
pass
- except (KeyboardInterrupt, ConnectionAbortedError), err:
+ except ConnectionAbortedError, err:
trans.setError(err)
except Exception, err:
urls = {}
Modified: Webware/trunk/WebKit/Docs/Configuration.txt
==============================================================================
--- Webware/trunk/WebKit/Docs/Configuration.txt (original)
+++ Webware/trunk/WebKit/Docs/Configuration.txt Sat Dec 8 04:08:03 2007
@@ -485,9 +485,9 @@
``MaxRequestTime``:
This setting controls automatic cancelation of long-running requests.
All worker threads executing requests longer than ``MaxRequestTime``
- seconds will be automatically aborted. The monitoring of long-running
- requests can be disabled by setting this to ``0`` or ``None``.
- Default: ``300``.
+ seconds will be automatically aborted with a ``RequestTooLongError``
+ exception. The monitoring of long-running requests can be disabled
+ by setting this to ``0`` or ``None``. Default: ``300``.
``CheckInterval``:
The number of virtual instructions after which Python will check
for thread switches, signal handlers, etc. This is passed directly
Modified: Webware/trunk/WebKit/ThreadedAppServer.py
==============================================================================
--- Webware/trunk/WebKit/ThreadedAppServer.py (original)
+++ Webware/trunk/WebKit/ThreadedAppServer.py Sat Dec 8 04:08:03 2007
@@ -84,6 +84,18 @@
class ProtocolError(Exception):
pass
+class ThreadAbortedError(Exception):
+ pass
+
+class RequestAbortedError(ThreadAbortedError):
+ pass
+
+class RequestTooLongError(RequestAbortedError):
+ pass
+
+class ServerShutDownError(ThreadAbortedError):
+ pass
+
class WorkerThread(Thread):
"""Base class for Webware worker threads that can be aborted.
@@ -104,7 +116,7 @@
self._threadID = threadID
return threadID
- def abort(self, exception=ConnectionAbortedError):
+ def abort(self, exception=ThreadAbortedError):
"""Abort the current thread by raising an exception in its context.
A return value of one means the thread was successfully aborted,
@@ -521,7 +533,7 @@
_canAbortRequest = WorkerThread._canAbort
- def abortRequest(self, requestID, exception=ConnectionAbortedError):
+ def abortRequest(self, requestID, exception=RequestAbortedError):
"""Abort a request by raising an exception in its worker thread.
A return value of one means the thread was successfully aborted,
@@ -593,7 +605,7 @@
raise KeyError
if verbose:
print "Aborting long-running request", requestID
- t.abort()
+ t.abort(RequestTooLongError)
except Exception:
pass
t._abortHandler = None
@@ -637,7 +649,7 @@
self._threadHandler[t] = handler
try:
handler.handleRequest()
- except ConnectionAbortedError:
+ except ThreadAbortedError:
print "Worker thread has been aborted"
except Exception:
traceback.print_exc(file=sys.stderr)
@@ -714,7 +726,7 @@
self._requestQueue.put(None)
if self._canAbortRequest:
for t in self._threadHandler.keys():
- t.abort()
+ t.abort(ServerShutDownError)
for t in self._threadPool:
try:
t.join()
|