Skip to content

Instantly share code, notes, and snippets.

@jhalcrow
Created March 22, 2012 23:58
Show Gist options
  • Save jhalcrow/2165629 to your computer and use it in GitHub Desktop.
Save jhalcrow/2165629 to your computer and use it in GitHub Desktop.
Gevent server-client livelock
import gevent.monkey; gevent.monkey.patch_all()
import gevent.server
from BaseHTTPServer import BaseHTTPRequestHandler
import urllib2
class DummyHTTPServer(gevent.server.StreamServer):
def handle(self, sock, addr):
handler = DummyHTTPHandler(sock, addr, self)
try:
handler.setup()
handler.handle()
finally:
handler.finish()
class DummyHTTPHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write("blah")
server = DummyHTTPServer(('',10000))
server.start()
test = urllib2.urlopen('http://localhost:10000').read()
print test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment