Reputation: 121
I have had trouble to kill uwsgi processes. Whenever I use below commands to shutdown uwsgi, another uwsgi workers respawned after a few seconds. So after shutdown uwsgi process and start up uwsgi server again, uwsgi processes continues to accumulate in memory.
cat /tmp/MyProject.pid
I want to know how to kill uwsgi processes not making uwsgi workers respawned. I attach ini file as below.
[uwsgi]
chdir = /home/data/MyProject/
module = MyProject.wsgi
home = /home/data/anaconda3/envs/env1
master = true
pidfile = /tmp/MyProject.pid
single-interpreter = true
die-on-term = true
processes = 4
socket = /home/data/MyProject/MyProject.sock
chmod-socket = 666
vacuum = true
Thank you in advance!!
Upvotes: 2
Views: 2627
Reputation: 9364
at first:
uwsgi
is a binary protocol that uWSGI uses to communicate with other servers. uWSGI
is an application server.-9
(SIGKILL
) to stop process if you care about child processes (workers)what I can say according your information:
Whenever I use below commands to shutdown uwsgi, another uwsgi workers respawned after a few seconds
Looks like you trying to kill worker (child) process but not uWSGI application server (master process). Here is processes = 4
in your config, so application server (master process) watching for minimum running workers (child processes). And if one of it exited (by KILL
signal or source code exception, no matter) application server starting new 4th process.
So after shutdown uwsgi process and start up uwsgi server again
If uwsgi process
is a worker (child process) - see answer above
If uwsgi process
is an application server (master process) - here is another problem. You using KILL
(-9
) signal to stop server. And that is not allow to exit application properly (see at first
's second point). So when your application server is unexpectedly killed, it leave all 4 child processes running without parent (master) process (say hello to orphaned process)
You should to use SIGTERM
instdead of SIGKILL
. Do you understand meaning of die-on-term = true
? Yeah! That means please stop stack of all processes on SIGTERM
.
uwsgi --stop /tmp/MyProject.pid
This command should stop all processes properly. Here is no information in your question to decide what problem that may be...
I have three guesses:
die-on-term = true
inverts the meanings of SIGTERM and SIGQUIT to uWSGI, so maybe stop
working like reload
in this case? not sure.In addition, you may check this helpful article to understand how to scale-in and scale-out child process dynamically to be able run all 4th processes only when it needed and run only 1 process when service is idle.
I created simple uWSGI application to check behaviour:
opt
`-- wsgi_example
|-- app.py
`-- wsgi.ini
[uwsgi]
chdir = /opt/wsgi_example
module = app
master = true
pidfile = /opt/wsgi_example/app.pid
single-interpreter = true
die-on-term = true
processes = 2
socket = /opt/wsgi_example/app.sock
chmod-socket = 666
vacuum = true
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
I running this application by wsgi wsgi.ini
I stopping this application by uwsgi --stop app.pid
Output is
spawned uWSGI master process (pid: 15797)
spawned uWSGI worker 1 (pid: 15798, cores: 1)
spawned uWSGI worker 2 (pid: 15799, cores: 1)
SIGINT/SIGQUIT received...killing workers...
worker 1 buried after 1 seconds
worker 2 buried after 1 seconds
goodbye to uWSGI.
VACUUM: pidfile removed.
VACUUM: unix socket /opt/wsgi_example/app.sock removed.
All working properly. All processes stopped.
Your question is not reproducible.
Search for the problem inside application code or your individual infrastructure configuration.
※ checked with uWSGI 2.0.8
and 2.0.19.1
and python 3.6.7
Upvotes: 1