开发者

Avoiding socket timeouts in SQLAlchemy

I'm new to SQLAlchemy, but I'm trying to use it to create and fill a database for a personal project. I've set pool_timeout to 43200 (twelve hours), but I'm still getting socket timeouts.

engine = sqlalchemy.create_engine(
            'postgresql+pg8000://gdwatson:pass@localhost/dbname',
            pool_timeout=43200)
db.tables.meta.drop_all(bind=engine)
db.tables.meta.create_all(bind=engine)

conn = engine.connect()
dataset = build_d开发者_StackOverflow社区ataset()
conn.execute(db.tables.mytable.insert(),
             dataset)
conn.close()

I end up getting socket.timeout: timed out after a good deal of processing time, but probably under an hour and certainly under two. It's actually three levels deep-- while handling the timeout exception another occurred, and then when handling that one yet another occurred. (Perhaps this is the library retrying?) The exception occurs in conn.execute, and I'm at a loss as to how to prevent it.

A search hasn't turned up anything informative. I am using Python 3.1 and SQLAlchemy 0.6.1, for what it's worth.


I don't know if this is the recommended method, but you could periodically send a SELECT 1 statement and ensure the connection isn't idle.
You could also look into this for some guidance

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜