2019-07-02 06:32:26 +00:00
|
|
|
from gevent.pywsgi import WSGIServer, WSGIHandler
|
|
|
|
from gevent import Timeout
|
|
|
|
class FDSafeHandler(WSGIHandler):
|
|
|
|
'''Our WSGI handler. Doesn't do much non-default except timeouts'''
|
|
|
|
def handle(self):
|
|
|
|
self.timeout = Timeout(120, Exception)
|
|
|
|
self.timeout.start()
|
|
|
|
try:
|
|
|
|
WSGIHandler.handle(self)
|
2019-08-05 16:30:19 +00:00
|
|
|
except gevent.Timeout as ex:
|
|
|
|
if ex is self.timeout:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
'''
|
2019-08-05 05:25:27 +00:00
|
|
|
def handle_error(self, two, three, four):
|
|
|
|
if two is self.timeout:
|
2019-07-02 06:32:26 +00:00
|
|
|
self.result = [b"Timeout"]
|
|
|
|
self.start_response("200 OK", [])
|
|
|
|
self.process_result()
|
|
|
|
else:
|
2019-08-05 16:30:19 +00:00
|
|
|
WSGIHandler.handle_error(self)
|
|
|
|
'''
|