import sqlalchemy.engine as engine
import os
from sqlalchemy.orm import sessionmaker
Session = sessionmaker(autoflush = True, transactional = True)
mysql_db = engine.create_engine('mysql://localhost/information_schema')
conn = mysql_db.connect()
sess = Session(bind = conn)
def handler(req):
global sess
conn = sess.connection()
req.content_type = 'text/plain'
req.write('pid = %d\n' % os.getpid())
req.write('thread_id = %d\n' % conn.connection.thread_id())
req.write('-----------------\n')
return 0
pid = 2879
thread_id = 60
-----------------
pid = 2881
thread_id = 62
-----------------
pid = 2879
thread_id = 60
-----------------
...
Чего же мне не хватает и можно ли это сделать на SQLAlchemy?