Skip to content

Instantly share code, notes, and snippets.

@colinmarc
Created April 17, 2012 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinmarc/2407326 to your computer and use it in GitHub Desktop.
Save colinmarc/2407326 to your computer and use it in GitHub Desktop.
makefile in gevent vs python2.7
#version with gevent
import gevent.socket as socket
from gevent import spawn
s = socket.socket()
s.bind(('', 9599))
s.listen(5)
def handle_client(client):
fd = client.makefile()
client.settimeout(1.0)
while True:
print("about to read")
d = fd.read(100)
print("READ", d)
if not d: break
print("WRITING")
fd.write(d)
while True:
print("before accept")
client, sockaddr = s.accept()
print("calling handler")
spawn(handle_client, client)
#version without gevent
import socket
s = socket.socket()
s.bind(('', 9599))
s.listen(5)
def handle_client(client):
fd = client.makefile()
client.settimeout(1.0)
while True:
print("about to read")
d = fd.read(100)
print("READ", d)
if not d: break
print("WRITING")
fd.write(d)
while True:
print("before accept")
client, sockaddr = s.accept()
print("calling handler")
handle_client(client)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment