How to use uWSGI - 10 common examples

To help you get started, we’ve selected a few uWSGI examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unbit / uwsgi / tests / websockets.py View on Github external
var value = document.getElementById('testo').value;
              s.send(value);
            }
          
     
    
        <h1>WebSocket</h1>
        <input id="testo" type="text">
        <input value="invia" type="button">
        <div style="width:640px;height:480px;background-color:black;color:white;border: solid 2px red;overflow:auto" id="blackboard">
        </div>
    
    
        """ % (ws_scheme, env['HTTP_HOST'])
    elif env['PATH_INFO'] == '/foobar/':
        uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', ''))
        print "websockets..."
        while True:
            msg = uwsgi.websocket_recv_nb()
            if msg:
                queue.put(msg)
            else:
                try:
                    wait_read(uwsgi.connection_fd(), 0.1)
                except gevent.socket.timeout:
                    try:
                        msg = queue.get_nowait()
                        uwsgi.websocket_send(msg)
                    except Exception:
                        pass
    return ""
github unbit / uwsgi / tests / websockets_chat_asyncio.py View on Github external
asyncio.Task(redis_wait(subscriber, f))

        # switch again
        f.greenlet.parent.switch()

        while True:
            # any redis message in the queue ?
            if f.done():
                msg = f.result()
                uwsgi.websocket_send("[%s] %s" % (time.time(), msg))
                # restart coroutine
                f = GreenFuture()
                asyncio.Task(redis_wait(subscriber, f))
            if myself.has_ws_msg:
                myself.has_ws_msg = False
                msg = uwsgi.websocket_recv_nb()
                if msg:
                    asyncio.Task(redis_publish(connection, msg))
            # switch again
            f.greenlet.parent.switch()
github unbit / uwsgi / tests / websockets.py View on Github external
<h1>WebSocket</h1>
        <input id="testo" type="text">
        <input value="invia" type="button">
        <div style="width:640px;height:480px;background-color:black;color:white;border: solid 2px red;overflow:auto" id="blackboard">
        </div>
    
    
        """ % (ws_scheme, env['HTTP_HOST'])
    elif env['PATH_INFO'] == '/foobar/':
        uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', ''))
        print "websockets..."
        while True:
            msg = uwsgi.websocket_recv_nb()
            if msg:
                queue.put(msg)
            else:
                try:
                    wait_read(uwsgi.connection_fd(), 0.1)
                except gevent.socket.timeout:
                    try:
                        msg = queue.get_nowait()
                        uwsgi.websocket_send(msg)
                    except Exception:
                        pass
    return ""
github unbit / uwsgi / tests / websockets.py View on Github external
""" % (ws_scheme, env['HTTP_HOST'])
    elif env['PATH_INFO'] == '/foobar/':
        uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', ''))
        print "websockets..."
        while True:
            msg = uwsgi.websocket_recv_nb()
            if msg:
                queue.put(msg)
            else:
                try:
                    wait_read(uwsgi.connection_fd(), 0.1)
                except gevent.socket.timeout:
                    try:
                        msg = queue.get_nowait()
                        uwsgi.websocket_send(msg)
                    except Exception:
                        pass
    return ""
github unbit / uwsgi / tests / websockets_chat_asyncio.py View on Github external
# add a 4 seconds timer to manage ping/pong
        asyncio.get_event_loop().call_later(4, ws_recv_msg, myself)

        # add a coroutine for redis messages
        f = GreenFuture()
        asyncio.Task(redis_wait(subscriber, f))

        # switch again
        f.greenlet.parent.switch()

        while True:
            # any redis message in the queue ?
            if f.done():
                msg = f.result()
                uwsgi.websocket_send("[%s] %s" % (time.time(), msg))
                # restart coroutine
                f = GreenFuture()
                asyncio.Task(redis_wait(subscriber, f))
            if myself.has_ws_msg:
                myself.has_ws_msg = False
                msg = uwsgi.websocket_recv_nb()
                if msg:
                    asyncio.Task(redis_publish(connection, msg))
            # switch again
            f.greenlet.parent.switch()
github unbit / uwsgi / tests / websockets.py View on Github external
<input value="invia" type="button">
        <div style="width:640px;height:480px;background-color:black;color:white;border: solid 2px red;overflow:auto" id="blackboard">
        </div>
    
    
        """ % (ws_scheme, env['HTTP_HOST'])
    elif env['PATH_INFO'] == '/foobar/':
        uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', ''))
        print "websockets..."
        while True:
            msg = uwsgi.websocket_recv_nb()
            if msg:
                queue.put(msg)
            else:
                try:
                    wait_read(uwsgi.connection_fd(), 0.1)
                except gevent.socket.timeout:
                    try:
                        msg = queue.get_nowait()
                        uwsgi.websocket_send(msg)
                    except Exception:
                        pass
    return ""
github unbit / uwsgi / tests / websockets_chat_asyncio.py View on Github external
print("websockets...")
        # a future for waiting for redis connection
        f = GreenFuture()
        asyncio.Task(redis_subscribe(f))
        # the result() method will switch greenlets if needed
        subscriber = f.result()

        # open another redis connection for publishing messages
        f0 = GreenFuture()
        t = asyncio.Task(redis_open(f0))
        connection = f0.result()

        myself = greenlet.getcurrent()
        myself.has_ws_msg = False
        # start monitoring websocket events
        asyncio.get_event_loop().add_reader(uwsgi.connection_fd(), ws_recv_msg, myself)

        # add a 4 seconds timer to manage ping/pong
        asyncio.get_event_loop().call_later(4, ws_recv_msg, myself)

        # add a coroutine for redis messages
        f = GreenFuture()
        asyncio.Task(redis_wait(subscriber, f))

        # switch again
        f.greenlet.parent.switch()

        while True:
            # any redis message in the queue ?
            if f.done():
                msg = f.result()
                uwsgi.websocket_send("[%s] %s" % (time.time(), msg))
github unbit / uwsgi / tests / psycopg2_green.py View on Github external
def async_wait(conn):
    # conn can be a connection or a cursor
    if not hasattr(conn, 'poll'):
        conn = conn.connection

    # interesting part: suspend until ready
    while True:
        state = conn.poll()
        if state == psycopg2.extensions.POLL_OK:
            break
        elif state == psycopg2.extensions.POLL_READ:
            uwsgi.wait_fd_read(conn.fileno())
            uwsgi.suspend()
        elif state == psycopg2.extensions.POLL_WRITE:
            uwsgi.wait_fd_write(conn.fileno())
            uwsgi.suspend()
        else:
            raise Exception("Unexpected result from poll: %r", state)
github unbit / uwsgi / tests / psycopg2_green.py View on Github external
def async_wait(conn):
    # conn can be a connection or a cursor
    if not hasattr(conn, 'poll'):
        conn = conn.connection

    # interesting part: suspend until ready
    while True:
        state = conn.poll()
        if state == psycopg2.extensions.POLL_OK:
            break
        elif state == psycopg2.extensions.POLL_READ:
            uwsgi.wait_fd_read(conn.fileno())
            uwsgi.suspend()
        elif state == psycopg2.extensions.POLL_WRITE:
            uwsgi.wait_fd_write(conn.fileno())
            uwsgi.suspend()
        else:
            raise Exception("Unexpected result from poll: %r", state)
github jaysonsantos / django-uwsgi-mail / test_project / uwsgidecorators.py View on Github external
import uwsgi
from threading import Thread

if uwsgi.masterpid() == 0:
    raise Exception("You must enable the uWSGI master process to use this module")

if uwsgi.opt.get('lazy'):
    raise Exception("uWSGI lazy mode is not supported by this module")

spooler_functions = {}
postfork_chain = []


def get_free_signal():
    for signum in xrange(0, 256):
        if not uwsgi.signal_registered(signum):
            return signum

    raise Exception("No free uwsgi signal available")


def manage_spool_request(vars):
    ret = spooler_functions[vars['ud_spool_func']](vars)