标签:style blog http color 使用 os io 数据
1
2
3
4
|
import eventlet pool
= eventlet.GreenPool() while True: pool.spawn(func,args
) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!
/usr/bin/env python #
-*- coding: UTF- 8 -*- from
eventlet import api def
httpd(writer,reader): req= ‘‘ while True: chunk=reader.readline() if not
chunk: break req+=chunk if chunk== ‘\r\n‘ : break data= ‘Hello
world!\r\n‘ writer.write( ‘HTTP/1.1
200 OK\r\nContent-Length: %d\r\n\r\n%s‘ %(len(data),data)) writer.close() reader.close() return def
main(): try : server=api.tcp_listener(( ‘0.0.0.0‘ , 3000 )) print ‘Server
started!‘ while True: conn,addr=server.accept() #print ‘client
%s connected!‘ %repr(addr) writer=conn.makefile( ‘w‘ ) api.spawn(httpd,writer,conn.makefile( ‘r‘ )) except
KeyboardInterrupt: pass return if __name__== ‘__main__‘ : main() |
python之高性能网络编程并发框架eventlet实例,布布扣,bubuko.com
标签:style blog http color 使用 os io 数据
原文地址:http://www.cnblogs.com/jingzhishen/p/3900936.html