Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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_dataset()
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.

like image 424
Grant Watson Avatar asked Nov 06 '22 09:11

Grant Watson


1 Answers

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

like image 130
Lelouch Lamperouge Avatar answered Nov 11 '22 04:11

Lelouch Lamperouge