def __call__(self, environ, start_response): self._sock = uwsgi.connection_fd() self.environ = environ uwsgi.websocket_handshake() self._req_ctx = None if hasattr(uwsgi, 'request_context'): # uWSGI >= 2.1.x with support for api access across-greenlets self._req_ctx = uwsgi.request_context() else: # use event and queue for sending messages from gevent.event import Event from gevent.queue import Queue from gevent.select import select self._event = Event() self._send_queue = Queue() # spawn a select greenlet def select_greenlet_runner(fd, event): """Sets event when data becomes available to read on fd.""" while True: event.set() try: select([fd], [], [])[0] except ValueError: break self._select_greenlet = gevent.spawn( select_greenlet_runner, self._sock, self._event) self.app(self)
def __call__(self, environ, start_response): self.environ = environ uwsgi.websocket_handshake() self._req_ctx = None if hasattr(uwsgi, 'request_context'): # uWSGI >= 2.1.x with support for api access across-greenlets self._req_ctx = uwsgi.request_context() else: # use event and queue for sending messages from gevent.event import Event from gevent.queue import Queue from gevent.select import select self._event = Event() self._send_queue = Queue() # spawn a select greenlet def select_greenlet_runner(fd, event): """Sets event when data becomes available to read on fd.""" while True: event.set() select([fd], [], [])[0] self._select_greenlet = gevent.spawn( select_greenlet_runner, uwsgi.connection_fd(), self._event) return self.app(self)
def __call__(self, environ, start_response): self._sock = uwsgi.connection_fd() self.environ = environ uwsgi.websocket_handshake() self._req_ctx = None if hasattr(uwsgi, 'request_context'): # uWSGI >= 2.1.x with support for api access across-greenlets self._req_ctx = uwsgi.request_context() else: # use event and queue for sending messages self._event = Event() self._send_queue = queue.Queue() # spawn a select greenlet def select_greenlet_runner(fd, event): """Sets event when data becomes available to read on fd.""" sel = selectors.DefaultSelector() sel.register(fd, selectors.EVENT_READ) try: while True: sel.select() event.set() except gevent.GreenletExit: sel.unregister(fd) self._select_greenlet = gevent.spawn( select_greenlet_runner, self._sock, self._event) self.app(self)
def application(environ, start_response): listner.start() if environ['PATH_INFO'] != '/': start_response('404 Not Found', [('Content-Type', 'text/html')]) return [b'<p>Page Not Found</p>\n'] uwsgi.websocket_handshake() connection = Connection(redis, environ['uwsgi.core']) connection.start(uwsgi.request_context()) return ''
def start(self): uwsgi.websocket_handshake() self.ctx = uwsgi.request_context() ClientManager.add(self) self.jobs.extend([ gevent.spawn(self._recv_job), gevent.spawn(self._send_job), ]) for j in self.jobs: j.link(self._exit) gevent.joinall(self.jobs)
def start(self): uwsgi.websocket_handshake() self.ctx = uwsgi.request_context() ClientManager.add(self) self.jobs.extend([ gevent.spawn(self._recv_job), gevent.spawn(self._send_job), ]) for j in self.jobs: j.link(self._exit) gevent.joinall(self.jobs)
def __init__(self): uwsgi.websocket_handshake() self.request_context = uwsgi.request_context()