Ticket #16: flup_timeout_patch_r2347.diff
| File flup_timeout_patch_r2347.diff, 3.5 kB (added by trac, 2 years ago) |
|---|
-
server/scgi_base.py
old new 37 37 import datetime 38 38 import os 39 39 import warnings 40 40 import traceback 41 41 # Threads are required. If you want a non-threaded (forking) version, look at 42 42 # SWAP <http://www.idyll.org/~t/www-tools/wsgi/>. 43 43 import thread … … 198 198 handlerTime.seconds + 199 199 handlerTime.microseconds / 1000000.0) 200 200 201 class TimeoutException(Exception): 202 pass 201 203 class Connection(object): 202 204 """ 203 205 Represents a single client (web server) connection. A single request 204 206 is handled, after which the socket is closed. 205 207 """ 206 def __init__(self, sock, addr, server ):208 def __init__(self, sock, addr, server, timeout): 207 209 self._sock = sock 208 210 self._addr = addr 209 211 self.server = server 212 self._timeout = timeout 210 213 211 214 self.logger = logging.getLogger(LoggerName) 212 215 216 def timeout_handler(self, signum, frame): 217 self.logger.error('Timeout Exceeded') 218 self.logger.error("\n".join(traceback.format_stack(frame))) 219 220 raise TimeoutException 221 213 222 def run(self): 214 223 if len(self._addr) == 2: 215 224 self.logger.debug('Connection starting up (%s:%d)', … … 264 273 # Allocate Request 265 274 req = Request(self, environ, input, output) 266 275 276 # If there is a timeout 277 if self._timeout: 278 old_alarm = signal.signal(signal.SIGALRM, self.timeout_handler) 279 signal.alarm(self._timeout) 280 267 281 # Run it. 268 282 req.run() 269 283 270 284 output.close() 271 285 input.close() 272 286 287 # Restore old handler if timeout was given 288 if self._timeout: 289 signal.signal(signal.SIGALRM, old_alarm) 290 291 292 273 293 class BaseSCGIServer(object): 274 294 # What Request class to use. 275 295 requestClass = Request -
server/scgi.py
old new 131 131 for key in ('jobClass', 'jobArgs'): 132 132 if kw.has_key(key): 133 133 del kw[key] 134 ThreadedServer.__init__(self, jobClass=Connection, jobArgs=(self, ),134 ThreadedServer.__init__(self, jobClass=Connection, jobArgs=(self,None), 135 135 **kw) 136 136 137 137 def run(self): -
server/scgi_fork.py
old new 90 90 def __init__(self, application, scriptName=NoDefault, environ=None, 91 91 bindAddress=('localhost', 4000), umask=None, 92 92 allowedServers=None, 93 loggingLevel=logging.INFO, debug=True, **kw):93 loggingLevel=logging.INFO, debug=True, timeout=None, **kw): 94 94 """ 95 95 scriptName is the initial portion of the URL path that "belongs" 96 96 to your application. It is used to determine PATH_INFO (which doesn't … … 130 130 for key in ('multithreaded', 'multiprocess', 'jobClass', 'jobArgs'): 131 131 if kw.has_key(key): 132 132 del kw[key] 133 PreforkServer.__init__(self, jobClass=Connection, jobArgs=(self,), **kw) 133 134 PreforkServer.__init__(self, jobClass=Connection, jobArgs=(self,timeout), **kw) 134 135 135 136 def run(self): 136 137 """