Created
April 17, 2012 16:31
-
-
Save colinmarc/2407326 to your computer and use it in GitHub Desktop.
makefile in gevent vs python2.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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