Hi,
I am writing a standalone program that uses SQLAlchemy for DB related
ops. The program is a log parser that runs continuously, processes the
log file and writes those entries to the database.
Connection to DB is done like so

engine = create_engine('mysql+mysqldb://root:root123@localhost/
mydb',pool_recycle=1800)
DBSession = sessionmaker(bind=engine)
session = DBSession()
Base = declarative_base()

Then my table def

class Statistics(Base):
    __tablename__ = 'statistics'
    col1 = Column(Integer,primary_key=True)
    col2 = Column(DateTime)

Finally somewhere deep in my processing code I write the values
(already arranged as a list of dictionaries) to the DB
session.execute(Statistics.__table__.insert().prefix_with(' ignore
'),entry_list)

The program runs well but I want it to handle server disconnects as
well (Perform book-keeping before raising exception and exiting
sanely).In the link (http://docs.sqlalchemy.org/en/rel_0_7/core/
pooling.html) you have explained a method of handling DB disconnects
'pessimistically' with a caveat "provided that the database server is
actually running". But how to handle server stoppage?

Currently the program throws an exception at execute()
OperationalError 2002 - Can't connect to server. Should I use try
except OperationalError for every DB statement? I tried using events
(connect, first_connect) but they don't fit

Regards

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to