Forums

Flask Concurrency And Timeouts

The flask .run method allows concurrency, but since I don't have run, how can I do something like

app.run( threaded = True ) ?

By the way, I am currently using the free version, so if it is not possible to do multi-threading there, how can I do set a connection timeout, such that flask stops handling a request after 20 seconds or so?

Thank you in advance!

It's not possible to run multiple threads on PythonAnywhere. We currently automatically terminate requests that take longer than a few minutes.

What are you trying to achieve with the timeout?

What if I want to run web app in async mode? I have something like :

if __name__ == '__main__':
if sio.async_mode == 'threading':
    # deploy with Werkzeug
    app.run(threaded=True)
elif sio.async_mode == 'eventlet':
    # deploy with eventlet
    import eventlet
    import eventlet.wsgi
    eventlet.wsgi.server(eventlet.listen(('', 5000)), app)
elif sio.async_mode == 'gevent':
    # deploy with gevent
    from gevent import pywsgi
    try:
        from geventwebsocket.handler import WebSocketHandler
        websocket = True
    except ImportError:
        websocket = False
    if websocket:
        pywsgi.WSGIServer(('', 5000), app,
                          handler_class=WebSocketHandler).serve_forever()
    else:
        pywsgi.WSGIServer(('', 5000), app).serve_forever()
elif sio.async_mode == 'gevent_uwsgi':
    print('Start the application through the uwsgi server. Example:')
    print('uwsgi --http :5000 --gevent 1000 --http-websockets --master '
          '--wsgi-file app.py --callable app')
else:
    print('Unknown async_mode: ' + sio.async_mode)

[edited by admin: formatting]

Unfortunately we do not support sockets/async mode for webapps at the moment