def application(env, start_response): try: uwsgi.register_rpc("A" * 300, hello) start_response('500 Buffer Overflow', [('Content-Type', 'text/plain')]) except ValueError: start_response('200 OK', [('Content-Type', 'text/plain')]) return ()
def __call__(self, f): uwsgi.register_rpc(self.name, f) return f
@args_as_unicode def key_type_token_mapper(key, key_type, token, route_extra, url): global db_conn # print 'key %s key_type %s token %s route_extra %s url %s\n' % (key, key_type, token, route_extra, url) if key and key_type and token: # sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id x and this is thread id y. # So try upto 2 times for i in range(2): # Order by rowid gives us the last row added try: row = db_conn.execute( "SELECT host, port FROM %s WHERE key=? AND key_type=? AND token=? ORDER BY rowid DESC LIMIT 1" % (DATABASE_TABLE_NAME), (key, key_type, token)).fetchone() if row: rval = '%s:%s' % (tuple(row)) return rval.encode() break except sqlite3.ProgrammingError: db_conn = sqlite3.connect(realtime_db_file) continue break return None uwsgi.register_rpc('rtt_key_type_token_mapper', key_type_token_mapper) uwsgi.register_rpc('rtt_key_type_token_mapper_cached', key_type_token_mapper_cached)
import uwsgi from flask import Flask import werkzeug #!flask/bin/python from app import app app.run(debug = True) domains['jelenakocic.in.rs'] = {'nodes': ('127.0.0.1:3031', '192.168.43.1:4343'), 'node': ˓ → 0} #app = Flask(__name__) @rpc('hello') def hellorpc(foo, bar): return "%s-%s-%s" (foo, bar) def hello(): return "Hello World" uwsgi.register_rpc("hello", hello) def helloapp(env, start_response): start_response('200 Ok', [('Content-Type', 'text/html')]) return uwsgi.rpc('127.0.0.1:3031', 'hello') def hello_file(num): print "/tmp has been modified !!!" def get(key): if key not in domains: return DEFAULT_NODE # get the node to forward requests to nodes = domains[key]['nodes'] current_node = domains[key]['node'] value = nodes[current_node] # round robin :P next_node = current_node + 1 if next_node >= len(nodes): next_node = 0
import uwsgi def hello(): return "Hello World" print uwsgi.register_rpc("hello", hello) print uwsgi.rpc(None, "hello")
import uwsgi def hello(): return "Hello World" print(uwsgi.register_rpc("hello", hello)) print(uwsgi.rpc(None, "hello"))
import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') log = logging.getLogger(__name__) def hello_world(): pid = os.getpid() log.info("%d enter"%(pid)) os.system("sleep 1") log.info(" %s work after sleep"%(pid)) log.info("%d exit"%(pid)) return "Hello World from pid %s\n"%(os.getpid()) def test1(s): pid = os.getpid() log.info("%d enter"%(pid)) os.system("sleep 3") log.info(" %s work after sleep"%(pid)) log.info("%d exit"%(pid)) return "test1 from pid %s: %s\n"%(os.getpid(),s) uwsgi.register_rpc("hello", hello_world) uwsgi.register_rpc("test1", test1) def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"]
from uwsgicc import app import uwsgi def hello_world(name): return "Hello World %s" % name uwsgi.register_rpc("hello", hello_world) uwsgi.set_warning_message("uWSGI is running the Control Center") application = app
def register_rpc(self, name, func): return uwsgi.register_rpc(name, func)