0

I am trying to use socket_io with my flask application. The problem is when i run database queries, like in the url_route function below. The first time the page loads properly but on consecutive calls the process goes into a blocking state. Even KeyboardInterrupt (Ctrl + c) terminates one of the python processes, i have to manually kill the other one.

One obvious solution would be to use a cache and use another script to run queries on database. Is there any other possible solution which could avoid running separate scripts?

@app.route('/status/<urlMap>')
def status(urlMap):
    dictResponse = {}
    data = models.Status.query.filter_by(urlmap = urlMap).first()
    if data.conversion == "DONE":
        dictResponse['conversion'] = 'success'
    if data.published == "DONE":
        dictResponse['publish'] = 'success'

    return render_template('status.html',status = dictResponse)

Also on removing the import flask.ext.socketio and using app.run(host='0.0.0.0') instead of socketio.run(app,host='0.0.0.0') the app runs perfectly. So i think its the async gevent calls thats somehow blocking the process.

codename_subho
  • 456
  • 8
  • 22

1 Answers1

0

Like @Miguel pointed out the problem correctly. monkey patching the standard libraries solved the issue.

monkey.patch_all() solved the problem.

codename_subho
  • 456
  • 8
  • 22