Hello,

Is below the way to reconnect to postgresql server automatically?
everytime I need to remake a session with
"Session  = sessionmaker(bind=engine)
session  = Session()"
, is this right?

the codes below can work, but if I don't remake the session, it will failed 
at server timeout.


#!/bin/env python

from urllib import quote_plus as urlquote
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker

Base = declarative_base()

engine = 
create_engine('postgresql+psycopg2://ngrs_reg:%[email protected]/arden_ngrs'%urlquote('ngrs_reg@123'),
 
echo=True, pool_recycle=599)

class Arch(Base):
  __tablename__ = 'arch'
  arch_id = Column(Integer, primary_key=True)
  arch_name = Column(String)


Session  = sessionmaker(bind=engine)
session  = Session()

#print  dir(session)

print dir(session.query(Arch))
for x in session.query(Arch):
  print x.arch_id, x.arch_name

import time
print 'sleeping'

#conn = session.connection()

# test timeout
time.sleep(3600)
print 'waken'

Session  = sessionmaker(bind=engine)
session  = Session()

print dir(session.query(Arch))
for x in session.query(Arch):
  print x.arch_id, x.arch_name
~                                                                   

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to