Add basic WSGI server using eventlet.db_pool

This commit is contained in:
R. Tyler Croy 2010-09-11 11:56:23 -07:00
parent 2ddb9a7217
commit 361afe5bb0
1 changed files with 30 additions and 0 deletions

30
server.py Normal file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env python
import eventlet
import eventlet.db_pool
import eventlet.wsgi
eventlet.monkey_patch()
import MySQLdb
__dbpool = eventlet.db_pool.ConnectionPool(MySQLdb, host='127.0.0.1',
user='root', passwd='', db='mysql')
def handler(env, start_response):
conn = None
try:
conn = __dbpool.get()
cursor = conn.cursor()
result = cursor.execute('''SELECT NOW()''')
now = cursor.fetchone()
start_response('200 OK', [('Content-Type', 'text/plain',)])
return ['Yay: %s\r\n' % now]
finally:
if conn:
__dbpool.put(conn)
if __name__ == '__main__':
eventlet.wsgi.server(eventlet.listen(('', 8080)), handler)