Python Flask web app hanging
<p>I'm very new to python programming, I'm trying to expose few terminal commands as a http call. I'm packaging this below code into a tar.gz using setup.py and extracting this on the server to run the code in nginx web server. once I instantiate the app.py code using below, the http calls work fine for few hours. Not sure what happens after that, the http pages show an error and I do see the app is running in the server. Can someone please help me with this</p>

<blockquote>
  <p>gunicorn --bind 0.0.0.0:8000 cstaradmin:app &amp;</p>
</blockquote>

<pre><code>#!/usr/bin/env python
from flask import Flask
from shelljob import proc
from flask import Response
from flask import json,jsonify

def get_pretty_print(json_object):
    return json.dumps(json_object, sort_keys=False, indent=4, separators=('\n',' '))

def read_process(g):
    while g.is_pending():
        lines=g.readlines()
        for proc,line in lines:
            yield line

app = Flask(__name__)

def has_no_empty_params(rule):
    defaults = rule.defaults if rule.defaults is not None else ()
    arguments = rule.arguments if rule.arguments is not None else ()
    return len(defaults) &gt;= len(arguments)


@app.route('/', methods = ['GET'])
def help():
    """Print available functions."""
    func_list = {}
    for rule in app.url_map.iter_rules():
        if rule.endpoint != 'static':
            func_list[rule.rule] = app.view_functions[rule.endpoint].__doc__
    return jsonify(func_list)

@app.route("/ps")
def IRR():
    IRR = ["ps"]
    g=proc.Group()
    p=g.run(IRR)
    return Response(read_process(g),mimetype= 'text/plain')
    def catch_all(path):
    return

if __name__ == "__main__":
    try:
        app.run(host='0.0.0.0',port=8000)
    except:
        pass
</code></pre>

<p>Error:</p>

<p>Internal Server Error The server encountered an internal error and was    unable to complete your request. Either the server is overloaded or there is an error in the application</p>

<pre><code>[2016-10-22 15:38:55,505] ERROR in app: Exception on /path/ToMy/command [GET]
    Traceback (most recent call last):
      File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
        response = self.full_dispatch_request()
      File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
        rv = self.dispatch_request()
      File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "/path/ToMyapp/admin/cstaradmin.py", line 42, in listnodes
        p=g.run(listnodes)
      File "/usr/lib/python2.7/site-packages/shelljob/proc.py", line 53, in run
        CommandException( e, "Group.run '{}' failed".format( cmd ) ).do_raise()
      File "/usr/lib/python2.7/site-packages/shelljob/proc.py", line 51, in run
        return self._run_impl( cmd, shell )
      File "/usr/lib/python2.7/site-packages/shelljob/proc.py", line 63, in _run_impl
        stdin = subprocess.PIPE, # needed to detach from calling terminal (other wacky things can happen)
      File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
        errread, errwrite)
      File "/usr/lib64/python2.7/subprocess.py", line 1216, in _execute_child
        errpipe_read, errpipe_write = self.pipe_cloexec()
      File "/usr/lib64/python2.7/subprocess.py", line 1168, in pipe_cloexec
        r, w = os.pipe()
    CommandException: ("Group.run '['nodetool', ' status']' failed", OSError(24, 'Too many open files'))
</code></pre>