0
votes

I have a RESTful API written in python using werkzeug. It runs with nginx/uWsgi. I would like to kill worker process when an internal error (LOST zookeeper session) occurs and let uWsgi will spawn a new worker.

If I call sys.exit(0), worker does not exit. Perhaps SystemExit or Exception is being caught somewhere. I am running as a service using init script with,

exec $root/run uwsgi --socket 127.0.0.1:3037 --master --workers 4 --threads 10 --harakiri 60 --die-on-term --thunder-lock --lazy-apps --py-tracebacker /tmp/ledgerwebtbsock --wsgi-file my_server.py --logto /my_server.py

1

1 Answers

2
votes
uwsgi --help | grep on-exception

Returns a bunch of options to control automatically restarting workers when a specific exception is raised:

--reload-on-exception                   reload a worker when an exception is raised
--reload-on-exception-type              reload a worker when a specific exception type is raised
--reload-on-exception-value             reload a worker when a specific exception value is raised
--reload-on-exception-repr              reload a worker when a specific exception type+value (language-specific) is raised

Check out slide 9 from Roberto de Ioris's 10 uWSGI tricks - DjangoDay 2012 presentation for more.