mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-08 06:31:58 +00:00
added signal sending in uwsgicc
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import uwsgi
|
||||
from uwsgidecorators import *
|
||||
|
||||
from uwsgicc import app as application
|
||||
|
||||
import time
|
||||
|
||||
|
||||
@rpc("helloworld")
|
||||
def hello_world():
|
||||
return "Hello World"
|
||||
|
||||
@signal(1)
|
||||
def what_time_is_it(num):
|
||||
print(time.asctime())
|
||||
|
||||
@@ -693,7 +693,7 @@ void master_loop(char **argv, char **environ) {
|
||||
char byte;
|
||||
rlen = read(uwsgi.emperor_fd, &byte, 1);
|
||||
if (rlen > 0) {
|
||||
uwsgi_log("received message %d from emperor\n", byte);
|
||||
uwsgi_log_verbose("received message %d from emperor\n", byte);
|
||||
// remove me
|
||||
if (byte == 0) {
|
||||
close(uwsgi.emperor_fd);
|
||||
@@ -883,7 +883,7 @@ void master_loop(char **argv, char **environ) {
|
||||
uwsgi_error("read()");
|
||||
}
|
||||
else if (rlen > 0) {
|
||||
uwsgi_log("received uwsgi signal %d from workers\n", uwsgi_signal);
|
||||
uwsgi_log_verbose("received uwsgi signal %d from a worker\n", uwsgi_signal);
|
||||
uwsgi_route_signal(uwsgi_signal);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -488,9 +488,11 @@ PyObject *py_uwsgi_signal(PyObject * self, PyObject * args) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("sending %d to master\n", uwsgi_signal);
|
||||
#endif
|
||||
|
||||
rlen = write(uwsgi.shared->worker_signal_pipe[1], &uwsgi_signal, 1);
|
||||
rlen = write(uwsgi.signal_socket, &uwsgi_signal, 1);
|
||||
if (rlen != 1) {
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
|
||||
@@ -775,7 +775,9 @@ int wsgi_req_accept(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log_verbose("master sent signal %d to worker %d\n", uwsgi_signal, uwsgi.mywid);
|
||||
#endif
|
||||
if (uwsgi_signal_handler(uwsgi_signal)) {
|
||||
uwsgi_log_verbose("error managing signal %d on worker %d\n", uwsgi_signal, uwsgi.mywid);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ $(document).ready(function() {
|
||||
<a name="top"></a>
|
||||
<h1>uWSGI <span class="small">{{uwsgi.version}}</span> Control Center</h1>
|
||||
<div class="anchor">
|
||||
<a href="#information">information</a> | <a href="#options">options</a> | <a href="#logs">logs</a> | <a href="#workers">workers</a> | <a href="#rpc">rpc</a> {% if uwsgi.cluster() %}| <a href="#cluster">cluster</a>{% endif %}
|
||||
<a href="#information">information</a> | <a href="#options">options</a> | <a href="#logs">logs</a> | <a href="#signals">signals</a> | <a href="#workers">workers</a> | <a href="#rpc">rpc</a> {% if uwsgi.cluster() %}| <a href="#cluster">cluster</a>{% endif %}
|
||||
</div>
|
||||
|
||||
{% with messages = get_flashed_messages() %}
|
||||
@@ -239,6 +239,21 @@ $(document).ready(function() {
|
||||
|
||||
</div>
|
||||
|
||||
<a name="signals"></a>
|
||||
<h3>Signals</h3>
|
||||
<div class="info">
|
||||
<form action="{{url_for('sig')}}" method="POST">
|
||||
<input type="text" size="3" name="signum" />
|
||||
<input type="submit" value="send uwsgi signal" />
|
||||
</form>
|
||||
|
||||
<div class="anchor">
|
||||
<a href="#top">back to top</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<a name="workers"></a>
|
||||
<h3>Workers</h3>
|
||||
<div class="info">
|
||||
|
||||
@@ -23,6 +23,15 @@ def log():
|
||||
flash("log message written")
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route("/sig", methods=['POST'])
|
||||
def sig():
|
||||
try:
|
||||
uwsgi.signal(int(request.form['signum']))
|
||||
flash("uwsgi signal sent")
|
||||
except:
|
||||
flash("unable to send signal")
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route("/rpc", methods=['POST'])
|
||||
def rpc():
|
||||
node = str(request.form['node'])
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import uwsgi
|
||||
|
||||
class rpc(object):
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def __call__(self, f):
|
||||
uwsgi.register_rpc(self.name, f)
|
||||
return f
|
||||
|
||||
class signal(object):
|
||||
|
||||
def __init__(self, num):
|
||||
self.num = num
|
||||
|
||||
def __call__(self, f):
|
||||
uwsgi.register_signal(self.num, "", f)
|
||||
return f
|
||||
Reference in New Issue
Block a user