Commits

Alessio Deiana committed 8463aa1

Prints a warning on long requests (>60s)

Comments (0)

Files changed (2)

src/invenio_devserver/config.py

 CONFIG_FILENAME = 'invenio.conf'
 LOCAL_CONFIG_FILENAME = 'invenio-local.conf'
 
+# Max time we have available to process a request
+REQUEST_TIMEOUT = 60
+
 try:
     import config_local
     for setting in dir(config_local):

src/invenio_devserver/serve.py

 
         def pdb_on_error(f, *args, **kwargs):
             try:
-                f(*args, **kwargs)
+                return f(*args, **kwargs)
             except:
                 pdb.post_mortem()
 
         wsgi_app = partial(pdb_on_error, wsgi_app)
 
+    def timed_out_request(f, *args, **kwargs):
+        def handler(signum, frame):
+            _log('info', "\033[01;31mYour request took more than %s" \
+                         " seconds to process\033[0m" % config.REQUEST_TIMEOUT)
+        signal.signal(signal.SIGALRM, handler)
+        signal.alarm(config.REQUEST_TIMEOUT)
+        try:
+            return f(*args, **kwargs)
+        finally:
+            signal.alarm(0)
+
+    wsgi_app = partial(timed_out_request, wsgi_app)
+
     run_simple(server_socket,
                wsgi_app,
                use_debugger=True,