Created
October 5, 2009 18:23
-
-
Save ieure/202322 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import threading | |
from sqlalchemy import create_engine | |
from sqlalchemy.orm import sessionmaker, scoped_session | |
engine = create_engine("mysql://testing:[email protected]/testing", | |
pool_size=20, strategy="threadlocal") | |
Session = scoped_session(sessionmaker(bind=engine)) | |
def query(): | |
sess = Session() | |
res = sess.execute("SELECT SLEEP(1);") | |
print threading.currentThread().getName() | |
print " :%s" % (tuple(res),) | |
sess.close() | |
print "Spawning threads" | |
threads = [threading.Thread(target=query) for n in range(10)] | |
for thread in threads: | |
thread.start() | |
for thread in threads: | |
thread.join() | |
print "%s complete" % thread.getName() | |
print "Terminating" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment