diff options
author | Marko Kreen | 2011-07-04 11:48:40 +0000 |
---|---|---|
committer | Marko Kreen | 2011-07-04 12:10:18 +0000 |
commit | f11861d8e0154def291a179e03d1015c78264824 (patch) | |
tree | 994f59277f529dfc34904a4cc7a5b86c579049bf /python/skytools/scripting.py | |
parent | 235ace2ca37098ce49ecb8937cd9b699bb14fc5c (diff) |
skytools.DBScript: drop connection if connect string has changed
.reload() happens between .work() calls, so it's safe to
drop connection on first .get_database()
Diffstat (limited to 'python/skytools/scripting.py')
-rw-r--r-- | python/skytools/scripting.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py index a8baffd6..3d175429 100644 --- a/python/skytools/scripting.py +++ b/python/skytools/scripting.py @@ -659,10 +659,15 @@ class DBScript(BaseScript): """ max_age = self.cf.getint('connection_lifetime', DEF_CONN_AGE) + if not cache: cache = dbname if cache in self.db_cache: + if connstr is None: + connstr = self.cf.get(dbname, '') dbc = self.db_cache[cache] + if connstr: + dbc.check_connstr(connstr) else: if not connstr: connstr = self.cf.get(dbname) @@ -950,6 +955,12 @@ class DBCachedConn(object): conn.close() except: pass + def check_connstr(self, connstr): + """Drop connection if connect string has changed. + """ + if self.loc != connstr: + self.reset() + |