Created
November 14, 2014 04:50
-
-
Save willkelly/888d971ae52f3f07cf3b to your computer and use it in GitHub Desktop.
test1
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
from sqlalchemy import create_engine, Column, Integer | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker | |
Base = declarative_base() | |
engine = create_engine('postgresql+psycopg2://testman:testmanpass@localhost:5432/testman') | |
class TestMan(Base): | |
__tablename__ = "testman" | |
id = Column(Integer, primary_key=True) | |
value = Column(Integer) | |
Base.metadata.create_all(engine) | |
Session = sessionmaker(bind=engine) | |
session1 = Session() | |
session2 = Session() | |
for i in xrange(10000): | |
session1.add(TestMan(value=i)) | |
session1.commit() | |
results = session1.query(TestMan).execution_options(stream_results=True).filter(TestMan.value >= 0).yield_per(20) | |
for count, r in enumerate(results): | |
if count % 100 == 0: | |
print "%s" % count | |
session2.delete(session2.query(TestMan).get(r.id)) | |
session2.commit() | |
print "Got here!" | |
session2.close() | |
print "SECOND GOT HERE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment