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== '
' : break data= 'Hello
world!
' writer.write( 'HTTP/1.1
200 OK
Content-Length: %d
%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() |