Flask socketio debug with eventlet and Redis spawns extra greenthreads? Flask socketio debug with eventlet and Redis spawns extra greenthreads? flask flask

Flask socketio debug with eventlet and Redis spawns extra greenthreads?


Add simple print(os.getpid()) and observe ps aux. You should notice there are two Python processes. Change DEBUG=False, and the "problem" is not reproducing, also there is one Python process now.

So the problem is that your code creates redisReader no matter if it's a "worker manager" or an actual "request handler" process. So, don't create and start that pool unconditionally. Consult Werkzeug documentation where is your "application init" event, and only start redisReader there.


The solution here was to put my threading into a function called by Flask:

def setupRedis():    pool = eventlet.GreenPool()    pool.spawn(redisReader)...app.before_first_request(setupRedis)

This solved the extra threads left behind on Werkzeug restarts.