> Hello all,
>
> When I use redis with gevent and uwsgi, some of my processes seem to hang.
> I’ve isolated the error I’m getting in the code snippet below.
>
> When I use the following command ( uwsgi --gevent 100 --socket
> 0.0.0.0:8000
> --protocol=http -w testapp -p 4 ) to have uwsgi run 4 workers I expected
> 'done' to be print 4 time to standard output, but it doesn't. If I remove
> the monkey patching, things works fine and I get the 'done' to print 4
> times. When I use one process, everything works find, but anymore then
> that
> and I would get the hanging problem.
>
> Any help would be appreciated.
>
> from gevent import monkey; monkey.patch_all()import redis, geventfrom
> flask import Flask
>
> application = Flask(__name__)
>
> r = redis.StrictRedis(host='localhost', port=6379, db=0)
> def setup_cache():
>     r.set('a', 'b')
>     print 'done'
>
> @application.route('/')def hello_world():
>     return 'Hello World!'
>
> gevent.spawn(setup_cache)
> if __name__ == "__main__":
>     application.run()
> _______________________________________________


you cannot share the redis socket between processes, you need to make a
new connection for each worker. You can use @postfork decorator or just
add --lazy-apps to initialize your code for every worker


-- 
Roberto De Ioris
http://unbit.com
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to