Skip to content

Instantly share code, notes, and snippets.

@yangjuven
Created March 7, 2012 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangjuven/1994035 to your computer and use it in GitHub Desktop.
Save yangjuven/1994035 to your computer and use it in GitHub Desktop.
Test gevent.queue in web.py.
#!/usr/bin/env python
# -*- coding: utf8 -*-
import web
import gevent
from gevent import queue
from gevent.timeout import Timeout
from gevent.hub import Waiter
from gevent.pywsgi import WSGIServer
from gevent import monkey
monkey.patch_all()
q = queue.Queue()
urls = (
'/', 'push'
)
class push(object):
def GET(self):
q.put("hello")
def starthandler():
while True:
print q.get()
if __name__ == "__main__":
gevent.spawn(starthandler)
application = web.application(urls, {'push': push}).wsgifunc()
WSGIServer(('', 8088), application).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment