[uWSGI] Sharing connection to socket.io?

Roberto De Ioris roberto at unbit.it
Wed Jul 20 21:21:15 CEST 2011


> 2011/7/20 Roberto De Ioris <roberto at unbit.it>:
>> Looks like you can make a connection at the startup of your app and
>> reuse it in each requests, but you will need to send a 'keepalive/ping'
>> packet to leave it open.
>
> But how can I access such connection ie. in Django? Best way would be
> to create socket in WSGI file and then have access to it in Django.
> How can I achieve that? I mean that part with accessing it in Django.
> __

in wsgi file:

from uwsgidecorators import *

socketioconnection = None

@postfork
def connect():
    socketioconnection = connectxXX


in django view:

# substitute my_wsgi with the name of your module
from my_wsgi import socketioconnection


def index(request):
    socketioconnection.send(...)


Thanks to @postfork each worker will get a different object (read:
connection) in socketioconnection


I have not tried it, but should work
-- 
Roberto De Ioris
http://unbit.it


More information about the uWSGI mailing list